tstor/src/fs/memory.go

50 lines
730 B
Go
Raw Normal View History

2021-11-23 12:05:49 +00:00
package fs
import (
"bytes"
)
var _ Filesystem = &Memory{}
type Memory struct {
Storage *storage
}
func NewMemory() *Memory {
return &Memory{
Storage: newStorage(nil),
}
}
func (fs *Memory) Open(filename string) (File, error) {
return fs.Storage.Get(filename)
}
func (fs *Memory) ReadDir(path string) (map[string]File, error) {
2021-11-29 10:07:54 +00:00
return fs.Storage.Children(path)
2021-11-23 12:05:49 +00:00
}
var _ File = &MemoryFile{}
type MemoryFile struct {
*bytes.Reader
}
func NewMemoryFile(data []byte) *MemoryFile {
return &MemoryFile{
Reader: bytes.NewReader(data),
}
}
func (d *MemoryFile) Size() int64 {
return int64(d.Reader.Len())
}
func (d *MemoryFile) IsDir() bool {
return false
}
func (d *MemoryFile) Close() (err error) {
return
}