44 lines
3.4 KiB
Go
Raw Normal View History

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-11-10 11:45:21 +00:00
package memstore ;import (_c "encoding/hex";_e "errors";_gf "fmt";_eb "github.com/unidoc/unioffice/common/tempstorage";_g "io";_fb "io/ioutil";_d "math/rand";_fc "sync";);
2021-06-16 07:10:52 +00:00
2021-11-10 11:45:21 +00:00
// Name returns the filename of the underlying memDataCell
func (_b *memFile )Name ()string {return _b ._ga ._bd };
2021-09-22 16:41:01 +00:00
// TempDir creates a name for a new temp directory using a pattern argument
2021-11-10 11:45:21 +00:00
func (_gad *memStorage )TempDir (pattern string )(string ,error ){return _bg (pattern ),nil };
2021-08-23 20:44:48 +00:00
2021-09-22 16:41:01 +00:00
// Read reads from the underlying memDataCell in order to implement Reader interface
2021-11-10 11:45:21 +00:00
func (_a *memFile )Read (p []byte )(int ,error ){_gg :=_a ._de ;_fg :=_a ._ga ._fbe ;_gfe :=int64 (len (p ));if _gfe > _fg {_gfe =_fg ;p =p [:_gfe ];};if _gg >=_fg {return 0,_g .EOF ;};_dc :=_gg +_gfe ;if _dc >=_fg {_dc =_fg ;};_dg :=copy (p ,_a ._ga ._cd [_gg :_dc ]);_a ._de =_dc ;return _dg ,nil ;};
2021-05-31 16:22:30 +00:00
2021-09-22 16:41:01 +00:00
// Open returns tempstorage File object by name
2021-11-10 11:45:21 +00:00
func (_ce *memStorage )Open (path string )(_eb .File ,error ){_ced ,_bf :=_ce ._fd .Load (path );if !_bf {return nil ,_e .New (_gf .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 {_ga :_ced .(*memDataCell )},nil ;};
2021-03-16 20:51:18 +00:00
2021-11-10 11:45:21 +00:00
// Close is not applicable in this implementation
func (_ebg *memFile )Close ()error {return nil };
2021-04-23 20:00:00 +00:00
2021-11-10 11:45:21 +00:00
// Add reads a file from a disk and adds it to the storage
func (_ab *memStorage )Add (path string )error {_ ,_gb :=_ab ._fd .Load (path );if _gb {return nil ;};_cf ,_aa :=_fb .ReadFile (path );if _aa !=nil {return _aa ;};_ab ._fd .Store (path ,&memDataCell {_bd :path ,_cd :_cf ,_fbe :int64 (len (_cf ))});return nil ;};
2021-07-30 17:03:26 +00:00
// Write writes to the end of the underlying memDataCell in order to implement Writer interface
2021-11-10 11:45:21 +00:00
func (_fe *memFile )Write (p []byte )(int ,error ){_fe ._ga ._cd =append (_fe ._ga ._cd ,p ...);_fe ._ga ._fbe +=int64 (len (p ));return len (p ),nil ;};type memDataCell struct{_bd string ;_cd []byte ;_fbe int64 ;};func _ee (_af int )(string ,error ){_ca :=make ([]byte ,_af );if _ ,_aad :=_d .Read (_ca );_aad !=nil {return "",_aad ;};return _c .EncodeToString (_ca ),nil ;};
2020-11-09 01:00:18 +00:00
2021-11-10 11:45:21 +00:00
// RemoveAll removes all files according to the dir argument prefix
func (_fbef *memStorage )RemoveAll (dir string )error {_fbef ._fd .Range (func (_bb ,_ec interface{})bool {_fbef ._fd .Delete (_bb );return true });return nil ;};type memFile struct{_ga *memDataCell ;_de int64 ;};
// SetAsStorage sets temp storage as a memory storage
func SetAsStorage (){_ggg :=memStorage {_fd :_fc .Map {}};_eb .SetAsStorage (&_ggg )};type memStorage struct{_fd _fc .Map };
// TempFile creates a new empty file in the storage and returns it
func (_gfef *memStorage )TempFile (dir ,pattern string )(_eb .File ,error ){_be :=dir +"\u002f"+_bg (pattern );_bfc :=&memDataCell {_bd :_be ,_cd :[]byte {}};_da :=&memFile {_ga :_bfc };_gfef ._fd .Store (_be ,_bfc );return _da ,nil ;};func _bg (_ff string )string {_cb ,_ :=_ee (6);return _ff +_cb };