summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/spf13/afero/mem/file.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/spf13/afero/mem/file.go')
-rw-r--r--vendor/github.com/spf13/afero/mem/file.go30
1 files changed, 24 insertions, 6 deletions
diff --git a/vendor/github.com/spf13/afero/mem/file.go b/vendor/github.com/spf13/afero/mem/file.go
index 5ef8b6a3..3cf4693b 100644
--- a/vendor/github.com/spf13/afero/mem/file.go
+++ b/vendor/github.com/spf13/afero/mem/file.go
@@ -18,15 +18,20 @@ import (
"bytes"
"errors"
"io"
+ "io/fs"
"os"
"path/filepath"
"sync"
"sync/atomic"
"time"
+
+ "github.com/spf13/afero/internal/common"
)
const FilePathSeparator = string(filepath.Separator)
+var _ fs.ReadDirFile = &File{}
+
type File struct {
// atomic requires 64-bit alignment for struct field access
at int64
@@ -183,10 +188,23 @@ func (f *File) Readdirnames(n int) (names []string, err error) {
return names, err
}
+// Implements fs.ReadDirFile
+func (f *File) ReadDir(n int) ([]fs.DirEntry, error) {
+ fi, err := f.Readdir(n)
+ if err != nil {
+ return nil, err
+ }
+ di := make([]fs.DirEntry, len(fi))
+ for i, f := range fi {
+ di[i] = common.FileInfoDirEntry{FileInfo: f}
+ }
+ return di, nil
+}
+
func (f *File) Read(b []byte) (n int, err error) {
f.fileData.Lock()
defer f.fileData.Unlock()
- if f.closed == true {
+ if f.closed {
return 0, ErrFileClosed
}
if len(b) > 0 && int(f.at) == len(f.fileData.data) {
@@ -214,7 +232,7 @@ func (f *File) ReadAt(b []byte, off int64) (n int, err error) {
}
func (f *File) Truncate(size int64) error {
- if f.closed == true {
+ if f.closed {
return ErrFileClosed
}
if f.readOnly {
@@ -236,7 +254,7 @@ func (f *File) Truncate(size int64) error {
}
func (f *File) Seek(offset int64, whence int) (int64, error) {
- if f.closed == true {
+ if f.closed {
return 0, ErrFileClosed
}
switch whence {
@@ -251,7 +269,7 @@ func (f *File) Seek(offset int64, whence int) (int64, error) {
}
func (f *File) Write(b []byte) (n int, err error) {
- if f.closed == true {
+ if f.closed {
return 0, ErrFileClosed
}
if f.readOnly {
@@ -330,8 +348,8 @@ func (s *FileInfo) Size() int64 {
var (
ErrFileClosed = errors.New("File is closed")
- ErrOutOfRange = errors.New("Out of range")
- ErrTooLarge = errors.New("Too large")
+ ErrOutOfRange = errors.New("out of range")
+ ErrTooLarge = errors.New("too large")
ErrFileNotFound = os.ErrNotExist
ErrFileExists = os.ErrExist
ErrDestinationExists = os.ErrExist