44 lines
3.3 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
package memstore ;import (_ede "encoding/hex";_fe "errors";_dc "fmt";_ge "github.com/unidoc/unioffice/common/tempstorage";_daf "io";_dfb "io/ioutil";_bd "math/rand";_ff "sync";);type memStorage struct{_g _ff .Map };
// Open returns tempstorage File object by name
func (_gg *memStorage )Open (path string )(_ge .File ,error ){_bc ,_ab :=_gg ._g .Load (path );if !_ab {return nil ,_fe .New (_dc .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 {_be :_bc .(*memDataCell )},nil ;};
// Name returns the filename of the underlying memDataCell
func (_da *memFile )Name ()string {return _da ._be ._ead };
// Write writes to the end of the underlying memDataCell in order to implement Writer interface
func (_dg *memFile )Write (p []byte )(int ,error ){_dg ._be ._cb =append (_dg ._be ._cb ,p ...);_dg ._be ._ea +=int64 (len (p ));return len (p ),nil ;};
// TempFile creates a new empty file in the storage and returns it
func (_ec *memStorage )TempFile (dir ,pattern string )(_ge .File ,error ){_a :=dir +"\u002f"+_fee (pattern );_e :=&memDataCell {_ead :_a ,_cb :[]byte {}};_dab :=&memFile {_be :_e };_ec ._g .Store (_a ,_e );return _dab ,nil ;};
// SetAsStorage sets temp storage as a memory storage
func SetAsStorage (){_cae :=memStorage {_g :_ff .Map {}};_ge .SetAsStorage (&_cae )};
// TempDir creates a name for a new temp directory using a pattern argument
func (_dbf *memStorage )TempDir (pattern string )(string ,error ){return _fee (pattern ),nil };
// Read reads from the underlying memDataCell in order to implement Reader interface
func (_df *memFile )Read (p []byte )(int ,error ){_cc :=_df ._dd ;_d :=_df ._be ._ea ;_f :=int64 (len (p ));if _f > _d {_f =_d ;p =p [:_f ];};if _cc >=_d {return 0,_daf .EOF ;};_af :=_cc +_f ;if _af >=_d {_af =_d ;};_baf :=copy (p ,_df ._be ._cb [_cc :_af ]);_df ._dd =_af ;return _baf ,nil ;};type memFile struct{_be *memDataCell ;_dd int64 ;};type memDataCell struct{_ead string ;_cb []byte ;_ea int64 ;};
// Add reads a file from a disk and adds it to the storage
func (_efa *memStorage )Add (path string )error {_ba ,_eab :=_dfb .ReadFile (path );if _eab !=nil {return _eab ;};_efa ._g .Store (path ,&memDataCell {_ead :path ,_cb :_ba });return nil ;};func _fee (_ef string )string {_db ,_ :=_cad (6);return _ef +_db };
// Close is not applicable in this implementation
func (_gd *memFile )Close ()error {return nil };func _cad (_ac int )(string ,error ){_bb :=make ([]byte ,_ac );if _ ,_ag :=_bd .Read (_bb );_ag !=nil {return "",_ag ;};return _ede .EncodeToString (_bb ),nil ;};
// RemoveAll removes all files according to the dir argument prefix
func (_c *memStorage )RemoveAll (dir string )error {_c ._g .Range (func (_ca ,_ad interface{})bool {_c ._g .Delete (_ca );return true });return nil ;};