diff --git a/memfile.go b/memfile.go index ceaf528..fcf80d2 100644 --- a/memfile.go +++ b/memfile.go @@ -45,6 +45,11 @@ type InMemoryFile struct { func MemFileCreate(name string) *InMemoryFile { return &InMemoryFile{name: name, mode: os.ModeTemporary, modtime: time.Now()} } + +func (f *InMemoryFile) Open() error { + atomic.StoreInt64(&f.at, 0) + f.closed = false + return nil } func (f *InMemoryFile) Close() error { diff --git a/memmap.go b/memmap.go index af3c653..d820502 100644 --- a/memmap.go +++ b/memmap.go @@ -152,9 +152,13 @@ func (m *MemMapFs) MkdirAll(path string, perm os.FileMode) error { func (m *MemMapFs) Open(name string) (File, error) { m.rlock() f, ok := m.getData()[name] - m.runlock() + ff, ok := f.(*InMemoryFile) + if ok { + ff.Open() + } + m.runlock() + if ok { - f.Seek(0, 0) return f, nil } else { return nil, ErrFileNotFound