Skip to content

Commit

Permalink
Make file interface a bit more interoperable
Browse files Browse the repository at this point in the history
  • Loading branch information
Camilo Aguilar committed Aug 5, 2020
1 parent d7a8afc commit 5082c90
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions memfs/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions test/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 5082c90

Please sign in to comment.