diff --git a/fs.go b/fs.go index a9efccd..d86f9d8 100644 --- a/fs.go +++ b/fs.go @@ -164,6 +164,8 @@ type File interface { // Name returns the name of the file as presented to Open. Name() string io.Writer + // TODO: Add io.WriterAt for v6 + // io.WriterAt io.Reader io.ReaderAt io.Seeker diff --git a/memfs/memory.go b/memfs/memory.go index 2e17a3c..978fed1 100644 --- a/memfs/memory.go +++ b/memfs/memory.go @@ -272,6 +272,10 @@ func (f *file) Seek(offset int64, whence int) (int64, error) { } func (f *file) Write(p []byte) (int, error) { + return f.WriteAt(p, f.position) +} + +func (f *file) WriteAt(p []byte, off int64) (int, error) { if f.isClosed { return 0, os.ErrClosed } @@ -280,8 +284,8 @@ func (f *file) Write(p []byte) (int, error) { return 0, errors.New("write not supported") } - n, err := f.content.WriteAt(p, f.position) - f.position += int64(n) + n, err := f.content.WriteAt(p, off) + f.position = off + int64(n) return n, err } diff --git a/test/mock.go b/test/mock.go index 40cbbf5..f782b26 100644 --- a/test/mock.go +++ b/test/mock.go @@ -115,6 +115,10 @@ func (*FileMock) ReadAt(b []byte, off int64) (int, error) { return 0, nil } +func (*FileMock) WriteAt(b []byte, off int64) (int, error) { + return 0, nil +} + func (*FileMock) Seek(offset int64, whence int) (int64, error) { return 0, nil }