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
|
2020-11-09 01:00:18 +00:00
|
|
|
package memstore ;import (_ef "encoding/hex";_ac "errors";_g "fmt";_ad "github.com/unidoc/unioffice/common/tempstorage";_c "io";_b "io/ioutil";_a "math/rand";_e "sync";);func _fc (_gg int )(string ,error ){_daf :=make ([]byte ,_gg );if _ ,_db :=_a .Read (_daf );_db !=nil {return "",_db ;};return _ef .EncodeToString (_daf ),nil ;};
|
2020-10-12 13:59:12 +00:00
|
|
|
|
2020-11-09 01:00:18 +00:00
|
|
|
// TempDir creates a name for a new temp directory using a pattern argument
|
|
|
|
func (_cb *memStorage )TempDir (pattern string )(string ,error ){return _ega (pattern ),nil };
|
2020-10-12 13:59:12 +00:00
|
|
|
|
|
|
|
// Close is not applicable in this implementation
|
2020-11-09 01:00:18 +00:00
|
|
|
func (_gf *memFile )Close ()error {return nil };func _ega (_cg string )string {_ce ,_ :=_fc (6);return _cg +_ce };
|
2020-08-31 22:58:25 +00:00
|
|
|
|
2020-10-12 13:59:12 +00:00
|
|
|
// TempFile creates a new empty file in the storage and returns it
|
2020-11-09 01:00:18 +00:00
|
|
|
func (_gdb *memStorage )TempFile (dir ,pattern string )(_ad .File ,error ){_bf :=dir +"\u002f"+_ega (pattern );_fg :=&memDataCell {_bc :_bf ,_efb :[]byte {}};_bfe :=&memFile {_eb :_fg };_gdb ._da .Store (_bf ,_fg );return _bfe ,nil ;};
|
2020-08-23 14:15:53 +00:00
|
|
|
|
2020-11-09 01:00:18 +00:00
|
|
|
// SetAsStorage sets temp storage as a memory storage
|
|
|
|
func SetAsStorage (){_bb :=memStorage {_da :_e .Map {}};_ad .SetAsStorage (&_bb )};
|
2020-08-23 14:15:53 +00:00
|
|
|
|
2020-11-09 01:00:18 +00:00
|
|
|
// Name returns the filename of the underlying memDataCell
|
|
|
|
func (_ea *memFile )Name ()string {return _ea ._eb ._bc };
|
2020-08-23 14:15:53 +00:00
|
|
|
|
2020-11-09 01:00:18 +00:00
|
|
|
// Write writes to the end of the underlying memDataCell in order to implement Writer interface
|
|
|
|
func (_dc *memFile )Write (p []byte )(int ,error ){_dc ._eb ._efb =append (_dc ._eb ._efb ,p ...);_dc ._eb ._adf +=int64 (len (p ));return len (p ),nil ;};type memStorage struct{_da _e .Map };
|
2020-10-12 13:59:12 +00:00
|
|
|
|
|
|
|
// RemoveAll removes all files according to the dir argument prefix
|
2020-11-09 01:00:18 +00:00
|
|
|
func (_afg *memStorage )RemoveAll (dir string )error {_afg ._da .Range (func (_egf ,_bbg interface{})bool {_afg ._da .Delete (_egf );return true });return nil ;};
|
2020-08-23 14:15:53 +00:00
|
|
|
|
2020-08-31 22:58:25 +00:00
|
|
|
// Open returns tempstorage File object by name
|
2020-11-09 01:00:18 +00:00
|
|
|
func (_fd *memStorage )Open (path string )(_ad .File ,error ){_fa ,_gfb :=_fd ._da .Load (path );if !_gfb {return nil ,_ac .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 {_eb :_fa .(*memDataCell )},nil ;};type memFile struct{_eb *memDataCell ;_gd int64 ;};
|
|
|
|
|
|
|
|
// Add reads a file from a disk and adds it to the storage
|
|
|
|
func (_afa *memStorage )Add (path string )error {_ ,_aec :=_afa ._da .Load (path );if _aec {return nil ;};_gdg ,_ga :=_b .ReadFile (path );if _ga !=nil {return _ga ;};_afa ._da .Store (path ,&memDataCell {_bc :path ,_efb :_gdg });return nil ;};type memDataCell struct{_bc string ;_efb []byte ;_adf int64 ;};
|
|
|
|
|
|
|
|
// Read reads from the underlying memDataCell in order to implement Reader interface
|
|
|
|
func (_d *memFile )Read (p []byte )(int ,error ){_ag :=_d ._gd ;_af :=_d ._eb ._adf ;_eg :=int64 (len (p ));if _eg > _af {_eg =_af ;p =p [:_eg ];};if _ag >=_af {return 0,_c .EOF ;};_gb :=_ag +_eg ;if _gb >=_af {_gb =_af ;};_ae :=copy (p ,_d ._eb ._efb [_ag :_gb ]);_d ._gd =_gb ;return _ae ,nil ;};
|