Skip to content

Commit 5082c90

Browse files
author
Camilo Aguilar
committed
Make file interface a bit more interoperable
1 parent d7a8afc commit 5082c90

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

fs.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,17 @@ type File interface {
173173
Lock() error
174174
// Unlock unlocks the file.
175175
Unlock() error
176+
// Readdir reads the contents of the directory associated with file and returns a
177+
// slice of up to n FileInfo values, as would be returned by Lstat, in directory order.
178+
// Subsequent calls on the same file will yield further FileInfos.
179+
// If n > 0, Readdir returns at most n FileInfo structures. In this case, if Readdir
180+
// returns an empty slice, it will return a non-nil error explaining why. At the end of
181+
// a directory, the error is io.EOF.
182+
// If n <= 0, Readdir returns all the FileInfo from the directory in a single slice.
183+
// In this case, if Readdir succeeds (reads all the way to the end of the directory),
184+
// it returns the slice and a nil error. If it encounters an error before the end of the directory,
185+
// Readdir returns the FileInfo read until that point and a non-nil error.
186+
Readdir(count int) ([]os.FileInfo, error)
176187
// Truncate the file.
177188
Truncate(size int64) error
178189
}

memfs/memory.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ func (f *file) Truncate(size int64) error {
289289
return nil
290290
}
291291

292+
func (f *file) Readdir(count int) ([]os.FileInfo, error) {
293+
// Not implemented
294+
return nil, nil
295+
}
296+
292297
func (f *file) Duplicate(filename string, mode os.FileMode, flag int) billy.File {
293298
new := &file{
294299
name: filename,

test/mock.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ func (*FileMock) Truncate(size int64) error {
135135
return nil
136136
}
137137

138+
func (*FileMock) Readdir(count int) ([]os.FileInfo, error) {
139+
return nil, nil
140+
}
141+
138142
type OnlyReadCapFs struct {
139143
BasicMock
140144
}

0 commit comments

Comments
 (0)