A small private collection of functionality for projects using http, rest and azure as a storage.
This is a collection of storage targets. All of them implement the IFileStorage interface. It allows to set a root directory to which all the paths are relative to.
type IFileStorage interface {
// CreateDirectory(dirName string) error
Write(fileName string, fileSize int64, reader io.ReadSeeker) error
Read(fileName string) (io.ReadCloser, error)
FileSize(fileName string) (int64, error)
DeleteDirectory(directory string) error
DeleteFile(fileName string) error
Walk(directory string, walk WalkFunc) error
Join(paths ...string) string
}
localStorage := localstorage.NewLocalStorage("./dir")
azureStorage := azurestorage.NewAzureStorage("accountName", "accountKey", "containerName")
Compress and Extract files and folders using gzip and tar. The compression and extraction is using the storage abstraction.
storage := localstorage.NewLocalStorage("dir")
// Create a new Compression object
compExtractor := compression.NewCompression(storage)
file, err := os.OpenFile("compress.tar.gz", os.O_CREATE|os.O_WRONLY, 0777)
if err != nil {
t.Errorf("Unable to open file: %v", err)
return
}
// compress ./dir/compressDir into compress.tar.gz
err = compressor.CompressDir("compressDir", file
Currently still a mess, trying to organize it better. Simple task is to have a directory from where files can be served. With backup and upload functionality:
- ability to upload files to a folder inside this directory using a tar.gz.
- download backup files of a folder inside this directory using a tar.gz.