2020-08-23 14:15:53 +00:00
|
|
|
//
|
|
|
|
// Copyright 2020 FoxyUtils ehf. All rights reserved.
|
|
|
|
//
|
|
|
|
// This is a commercial product and requires a license to operate.
|
|
|
|
// A trial license can be obtained at https://unidoc.io
|
|
|
|
//
|
|
|
|
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by the UniDoc End User License Agreement
|
|
|
|
// terms that can be accessed at https://unidoc.io/eula/
|
|
|
|
|
|
|
|
// Package memstore implements tempStorage interface
|
|
|
|
// by using memory as a storage
|
2021-03-16 20:51:18 +00:00
|
|
|
package memstore ;import (_ba "encoding/hex";_eg "errors";_g "fmt";_gd "github.com/unidoc/unioffice/common/tempstorage";_b "io";_bb "io/ioutil";_c "math/rand";_e "sync";);
|
2020-10-12 13:59:12 +00:00
|
|
|
|
2021-03-16 20:51:18 +00:00
|
|
|
// SetAsStorage sets temp storage as a memory storage
|
|
|
|
func SetAsStorage (){_cf :=memStorage {_cd :_e .Map {}};_gd .SetAsStorage (&_cf )};
|
2020-10-12 13:59:12 +00:00
|
|
|
|
2021-01-04 16:11:39 +00:00
|
|
|
// TempDir creates a name for a new temp directory using a pattern argument
|
2021-03-16 20:51:18 +00:00
|
|
|
func (_dag *memStorage )TempDir (pattern string )(string ,error ){return _gb (pattern ),nil };func _ea (_gba int )(string ,error ){_ad :=make ([]byte ,_gba );if _ ,_ff :=_c .Read (_ad );_ff !=nil {return "",_ff ;};return _ba .EncodeToString (_ad ),nil ;};
|
2021-01-04 16:11:39 +00:00
|
|
|
|
2021-03-16 20:51:18 +00:00
|
|
|
// Write writes to the end of the underlying memDataCell in order to implement Writer interface
|
|
|
|
func (_da *memFile )Write (p []byte )(int ,error ){_da ._bab ._bag =append (_da ._bab ._bag ,p ...);_da ._bab ._fd +=int64 (len (p ));return len (p ),nil ;};
|
2020-08-31 22:58:25 +00:00
|
|
|
|
2021-03-16 20:51:18 +00:00
|
|
|
// Open returns tempstorage File object by name
|
|
|
|
func (_bagb *memStorage )Open (path string )(_gd .File ,error ){_gdc ,_dg :=_bagb ._cd .Load (path );if !_dg {return nil ,_eg .New (_g .Sprintf ("\u0043\u0061\u006eno\u0074\u0020\u006f\u0070\u0065\u006e\u0020\u0074\u0068\u0065\u0020\u0066\u0069\u006c\u0065\u0020\u0025\u0073",path ));};return &memFile {_bab :_gdc .(*memDataCell )},nil ;};
|
|
|
|
|
|
|
|
// Name returns the filename of the underlying memDataCell
|
|
|
|
func (_dd *memFile )Name ()string {return _dd ._bab ._cgb };
|
2020-08-23 14:15:53 +00:00
|
|
|
|
2021-01-04 16:11:39 +00:00
|
|
|
// Read reads from the underlying memDataCell in order to implement Reader interface
|
2021-03-16 20:51:18 +00:00
|
|
|
func (_eb *memFile )Read (p []byte )(int ,error ){_gc :=_eb ._be ;_a :=_eb ._bab ._fd ;_cg :=int64 (len (p ));if _cg > _a {_cg =_a ;p =p [:_cg ];};if _gc >=_a {return 0,_b .EOF ;};_ac :=_gc +_cg ;if _ac >=_a {_ac =_a ;};_f :=copy (p ,_eb ._bab ._bag [_gc :_ac ]);_eb ._be =_ac ;return _f ,nil ;};type memDataCell struct{_cgb string ;_bag []byte ;_fd int64 ;};
|
2020-08-23 14:15:53 +00:00
|
|
|
|
2021-03-16 20:51:18 +00:00
|
|
|
// TempFile creates a new empty file in the storage and returns it
|
|
|
|
func (_db *memStorage )TempFile (dir ,pattern string )(_gd .File ,error ){_ddc :=dir +"\u002f"+_gb (pattern );_dae :=&memDataCell {_cgb :_ddc ,_bag :[]byte {}};_ga :=&memFile {_bab :_dae };_db ._cd .Store (_ddc ,_dae );return _ga ,nil ;};
|
2020-10-12 13:59:12 +00:00
|
|
|
|
2021-03-16 20:51:18 +00:00
|
|
|
// Add reads a file from a disk and adds it to the storage
|
|
|
|
func (_ed *memStorage )Add (path string )error {_ ,_bd :=_ed ._cd .Load (path );if _bd {return nil ;};_ebc ,_fdd :=_bb .ReadFile (path );if _fdd !=nil {return _fdd ;};_ed ._cd .Store (path ,&memDataCell {_cgb :path ,_bag :_ebc ,_fd :int64 (len (_ebc ))});return nil ;};
|
2020-08-23 14:15:53 +00:00
|
|
|
|
2021-03-16 20:51:18 +00:00
|
|
|
// RemoveAll removes all files according to the dir argument prefix
|
|
|
|
func (_ebe *memStorage )RemoveAll (dir string )error {_ebe ._cd .Range (func (_ce ,_ddcb interface{})bool {_ebe ._cd .Delete (_ce );return true });return nil ;};func _gb (_df string )string {_bagbc ,_ :=_ea (6);return _df +_bagbc };type memStorage struct{_cd _e .Map };type memFile struct{_bab *memDataCell ;_be int64 ;};
|
2020-11-09 01:00:18 +00:00
|
|
|
|
2021-01-04 16:11:39 +00:00
|
|
|
// Close is not applicable in this implementation
|
2021-03-16 20:51:18 +00:00
|
|
|
func (_ee *memFile )Close ()error {return nil };
|