From 5082c907eacad0eff8181cd1442fea3c2d75fdfd Mon Sep 17 00:00:00 2001 From: Camilo Aguilar Date: Wed, 5 Aug 2020 12:59:23 -0400 Subject: [PATCH] Make file interface a bit more interoperable --- fs.go | 11 +++++++++++ memfs/memory.go | 5 +++++ test/mock.go | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/fs.go b/fs.go index a9efccd..b540f7c 100644 --- a/fs.go +++ b/fs.go @@ -173,6 +173,17 @@ type File interface { Lock() error // Unlock unlocks the file. Unlock() error + // Readdir reads the contents of the directory associated with file and returns a + // slice of up to n FileInfo values, as would be returned by Lstat, in directory order. + // Subsequent calls on the same file will yield further FileInfos. + // If n > 0, Readdir returns at most n FileInfo structures. In this case, if Readdir + // returns an empty slice, it will return a non-nil error explaining why. At the end of + // a directory, the error is io.EOF. + // If n <= 0, Readdir returns all the FileInfo from the directory in a single slice. + // In this case, if Readdir succeeds (reads all the way to the end of the directory), + // it returns the slice and a nil error. If it encounters an error before the end of the directory, + // Readdir returns the FileInfo read until that point and a non-nil error. + Readdir(count int) ([]os.FileInfo, error) // Truncate the file. Truncate(size int64) error } diff --git a/memfs/memory.go b/memfs/memory.go index d4ac056..4f4fc07 100644 --- a/memfs/memory.go +++ b/memfs/memory.go @@ -289,6 +289,11 @@ func (f *file) Truncate(size int64) error { return nil } +func (f *file) Readdir(count int) ([]os.FileInfo, error) { + // Not implemented + return nil, nil +} + func (f *file) Duplicate(filename string, mode os.FileMode, flag int) billy.File { new := &file{ name: filename, diff --git a/test/mock.go b/test/mock.go index 40cbbf5..0d40bb3 100644 --- a/test/mock.go +++ b/test/mock.go @@ -135,6 +135,10 @@ func (*FileMock) Truncate(size int64) error { return nil } +func (*FileMock) Readdir(count int) ([]os.FileInfo, error) { + return nil, nil +} + type OnlyReadCapFs struct { BasicMock }