Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make file interface a bit more interoperable #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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