2021-04-23 20:00:00 +00:00

44 lines
3.4 KiB
Go

//
// 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
package memstore ;import (_e "encoding/hex";_gg "errors";_d "fmt";_ggb "github.com/unidoc/unioffice/common/tempstorage";_ac "io";_g "io/ioutil";_f "math/rand";_c "sync";);type memFile struct{_ff *memDataCell ;_db int64 ;};
// Add reads a file from a disk and adds it to the storage
func (_gda *memStorage )Add (path string )error {_ ,_ag :=_gda ._gf .Load (path );if _ag {return nil ;};_gee ,_ce :=_g .ReadFile (path );if _ce !=nil {return _ce ;};_gda ._gf .Store (path ,&memDataCell {_dc :path ,_gc :_gee ,_fb :int64 (len (_gee ))});return nil ;};
// TempDir creates a name for a new temp directory using a pattern argument
func (_ea *memStorage )TempDir (pattern string )(string ,error ){return _cb (pattern ),nil };
// Name returns the filename of the underlying memDataCell
func (_ga *memFile )Name ()string {return _ga ._ff ._dc };
// Read reads from the underlying memDataCell in order to implement Reader interface
func (_b *memFile )Read (p []byte )(int ,error ){_ggg :=_b ._db ;_cc :=_b ._ff ._fb ;_fg :=int64 (len (p ));if _fg > _cc {_fg =_cc ;p =p [:_fg ];};if _ggg >=_cc {return 0,_ac .EOF ;};_ffg :=_ggg +_fg ;if _ffg >=_cc {_ffg =_cc ;};_fc :=copy (p ,_b ._ff ._gc [_ggg :_ffg ]);_b ._db =_ffg ;return _fc ,nil ;};func _gce (_bc int )(string ,error ){_fga :=make ([]byte ,_bc );if _ ,_cbf :=_f .Read (_fga );_cbf !=nil {return "",_cbf ;};return _e .EncodeToString (_fga ),nil ;};type memDataCell struct{_dc string ;_gc []byte ;_fb int64 ;};
// Open returns tempstorage File object by name
func (_dbc *memStorage )Open (path string )(_ggb .File ,error ){_cg ,_ge :=_dbc ._gf .Load (path );if !_ge {return nil ,_gg .New (_d .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 {_ff :_cg .(*memDataCell )},nil ;};
// RemoveAll removes all files according to the dir argument prefix
func (_fff *memStorage )RemoveAll (dir string )error {_fff ._gf .Range (func (_ccf ,_dd interface{})bool {_fff ._gf .Delete (_ccf );return true });return nil ;};func _cb (_bb string )string {_ef ,_ :=_gce (6);return _bb +_ef };type memStorage struct{_gf _c .Map };
// TempFile creates a new empty file in the storage and returns it
func (_gaa *memStorage )TempFile (dir ,pattern string )(_ggb .File ,error ){_fd :=dir +"\u002f"+_cb (pattern );_aa :=&memDataCell {_dc :_fd ,_gc :[]byte {}};_ae :=&memFile {_ff :_aa };_gaa ._gf .Store (_fd ,_aa );return _ae ,nil ;};
// Write writes to the end of the underlying memDataCell in order to implement Writer interface
func (_ec *memFile )Write (p []byte )(int ,error ){_ec ._ff ._gc =append (_ec ._ff ._gc ,p ...);_ec ._ff ._fb +=int64 (len (p ));return len (p ),nil ;};
// SetAsStorage sets temp storage as a memory storage
func SetAsStorage (){_gd :=memStorage {_gf :_c .Map {}};_ggb .SetAsStorage (&_gd )};
// Close is not applicable in this implementation
func (_fgg *memFile )Close ()error {return nil };