48 lines
3.8 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
2022-02-05 13:05:36 +00:00
package memstore ;import (_cef "encoding/hex";_ce "errors";_g "fmt";_ca "github.com/unidoc/unioffice/common/tempstorage";_e "io";_eb "io/ioutil";_ef "math/rand";_cg "sync";);
2021-06-16 07:10:52 +00:00
2022-02-05 13:05:36 +00:00
// TempFile creates a new empty file in the storage and returns it
func (_ebc *memStorage )TempFile (dir ,pattern string )(_ca .File ,error ){_gd :=dir +"\u002f"+_cdb (pattern );_gg :=&memDataCell {_cc :_gd ,_efd :[]byte {}};_ag :=&memFile {_ec :_gg };_ebc ._f .Store (_gd ,_gg );return _ag ,nil ;};type memDataCell struct{_cc string ;_efd []byte ;_gf int64 ;};func _cdb (_bg string )string {_egb ,_ :=_ea (6);return _bg +_egb };
2021-08-23 20:44:48 +00:00
2022-02-05 13:05:36 +00:00
// RemoveAll removes all files according to the dir argument prefix
func (_ff *memStorage )RemoveAll (dir string )error {_ff ._f .Range (func (_fa ,_ad interface{})bool {_ff ._f .Delete (_fa );return true });return nil ;};
2021-05-31 16:22:30 +00:00
2021-09-22 16:41:01 +00:00
// Open returns tempstorage File object by name
2022-02-05 13:05:36 +00:00
func (_ac *memStorage )Open (path string )(_ca .File ,error ){_d ,_cd :=_ac ._f .Load (path );if !_cd {return nil ,_ce .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 {_ec :_d .(*memDataCell )},nil ;};
2022-01-15 21:17:38 +00:00
2022-02-05 13:05:36 +00:00
// SetAsStorage sets temp storage as a memory storage
func SetAsStorage (){_ab :=memStorage {_f :_cg .Map {}};_ca .SetAsStorage (&_ab )};func _ea (_de int )(string ,error ){_abfb :=make ([]byte ,_de );if _ ,_faf :=_ef .Read (_abfb );_faf !=nil {return "",_faf ;};return _cef .EncodeToString (_abfb ),nil ;};
2022-01-15 21:17:38 +00:00
2022-02-05 13:05:36 +00:00
// Read reads from the underlying memDataCell in order to implement Reader interface
func (_a *memFile )Read (p []byte )(int ,error ){_ecb :=_a ._ceb ;_ed :=_a ._ec ._gf ;_b :=int64 (len (p ));if _b > _ed {_b =_ed ;p =p [:_b ];};if _ecb >=_ed {return 0,_e .EOF ;};_gc :=_ecb +_b ;if _gc >=_ed {_gc =_ed ;};_bb :=copy (p ,_a ._ec ._efd [_ecb :_gc ]);_a ._ceb =_gc ;return _bb ,nil ;};
2022-01-15 21:17:38 +00:00
2022-02-05 13:05:36 +00:00
// Write writes to the end of the underlying memDataCell in order to implement Writer interface
func (_bf *memFile )Write (p []byte )(int ,error ){_bf ._ec ._efd =append (_bf ._ec ._efd ,p ...);_bf ._ec ._gf +=int64 (len (p ));return len (p ),nil ;};
2021-03-16 20:51:18 +00:00
2022-02-05 13:05:36 +00:00
// TempDir creates a name for a new temp directory using a pattern argument
func (_fb *memStorage )TempDir (pattern string )(string ,error ){return _cdb (pattern ),nil };type memFile struct{_ec *memDataCell ;_ceb int64 ;};
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
2022-02-05 13:05:36 +00:00
func (_eg *memStorage )Add (path string )error {_ ,_acb :=_eg ._f .Load (path );if _acb {return nil ;};_dd ,_gfc :=_eb .ReadFile (path );if _gfc !=nil {return _gfc ;};_eg ._f .Store (path ,&memDataCell {_cc :path ,_efd :_dd ,_gf :int64 (len (_dd ))});return nil ;};
2020-11-09 01:00:18 +00:00
2022-02-05 13:05:36 +00:00
// Close is not applicable in this implementation
func (_ced *memFile )Close ()error {return nil };
2021-11-10 11:45:21 +00:00
2022-02-05 13:05:36 +00:00
// Name returns the filename of the underlying memDataCell
func (_cf *memFile )Name ()string {return _cf ._ec ._cc };
2021-11-10 11:45:21 +00:00
2022-02-05 13:05:36 +00:00
// ReadAt reads from the underlying memDataCell at an offset provided in order to implement ReaderAt interface.
// It does not affect f.readOffset.
func (_aa *memFile )ReadAt (p []byte ,readOffset int64 )(int ,error ){_cgf :=_aa ._ec ._gf ;_ceba :=int64 (len (p ));if _ceba > _cgf {_ceba =_cgf ;p =p [:_ceba ];};if readOffset >=_cgf {return 0,_e .EOF ;};_cb :=readOffset +_ceba ;if _cb >=_cgf {_cb =_cgf ;};_cgc :=copy (p ,_aa ._ec ._efd [readOffset :_cb ]);return _cgc ,nil ;};type memStorage struct{_f _cg .Map };