Skip to content

Commit

Permalink
aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
ungerik committed Aug 28, 2023
1 parent 5280d84 commit e80d166
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 98 deletions.
3 changes: 1 addition & 2 deletions dropboxfs/dropboxfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"errors"
"io"
iofs "io/fs"
"path"
"strings"
Expand Down Expand Up @@ -345,7 +344,7 @@ func (dbfs *DropboxFileSystem) OpenReader(filePath string) (iofs.File, error) {
return fsimpl.NewReadonlyFileBuffer(data, info), nil
}

func (dbfs *DropboxFileSystem) OpenWriter(filePath string, perm []fs.Permissions) (io.WriteCloser, error) {
func (dbfs *DropboxFileSystem) OpenWriter(filePath string, perm []fs.Permissions) (fs.WriteCloser, error) {
if !dbfs.info(path.Dir(filePath)).IsDir {
return nil, fs.NewErrIsNotDirectory(dbfs.File(path.Dir(filePath)))
}
Expand Down
12 changes: 6 additions & 6 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
iofs "io/fs"
"strings"
"time"

Expand Down Expand Up @@ -186,7 +186,7 @@ func (file File) Joinf(format string, args ...interface{}) File {
}

// Stat returns a standard library io/fs.FileInfo describing the file.
func (file File) Stat() (fs.FileInfo, error) {
func (file File) Stat() (iofs.FileInfo, error) {
if file == "" {
return nil, ErrEmptyPath
}
Expand Down Expand Up @@ -693,7 +693,7 @@ func (file File) ReadFrom(reader io.Reader) (n int64, err error) {
if file == "" {
return 0, ErrEmptyPath
}
var writer io.WriteCloser
var writer WriteCloser
existingPerm := file.Permissions()
if existingPerm != NoPermissions {
writer, err = file.OpenWriter(existingPerm)
Expand All @@ -708,7 +708,7 @@ func (file File) ReadFrom(reader io.Reader) (n int64, err error) {
}

// OpenReader opens the file and returns a io/fs.File that has to be closed after reading
func (file File) OpenReader() (fs.File, error) {
func (file File) OpenReader() (ReadCloser, error) {
if file == "" {
return nil, ErrEmptyPath
}
Expand Down Expand Up @@ -740,15 +740,15 @@ func (file File) OpenReadSeeker() (ReadSeekCloser, error) {
return fsimpl.NewReadonlyFileBufferReadAll(readCloser, info)
}

func (file File) OpenWriter(perm ...Permissions) (io.WriteCloser, error) {
func (file File) OpenWriter(perm ...Permissions) (WriteCloser, error) {
if file == "" {
return nil, ErrEmptyPath
}
fileSystem, path := file.ParseRawURI()
return fileSystem.OpenWriter(path, perm)
}

func (file File) OpenAppendWriter(perm ...Permissions) (io.WriteCloser, error) {
func (file File) OpenAppendWriter(perm ...Permissions) (WriteCloser, error) {
if file == "" {
return nil, ErrEmptyPath
}
Expand Down
6 changes: 3 additions & 3 deletions fileinfo.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fs

import (
"io/fs"
iofs "io/fs"
"os"
"time"
)
Expand All @@ -26,7 +26,7 @@ type FileInfo struct {
// of an existing file.
// Use NewNonExistingFileInfo to get
// a FileInfo for non existing file.
func NewFileInfo(file File, info fs.FileInfo, hidden bool) FileInfo {
func NewFileInfo(file File, info iofs.FileInfo, hidden bool) FileInfo {
mode := info.Mode()
return FileInfo{
File: file,
Expand Down Expand Up @@ -58,7 +58,7 @@ func NewNonExistingFileInfo(file File) FileInfo {

// StdFileInfo returns an io/fs.FileInfo wrapper
// for the data stored in the FileInfo struct.
func (i *FileInfo) StdFileInfo() fs.FileInfo { return fileInfo{i} }
func (i *FileInfo) StdFileInfo() iofs.FileInfo { return fileInfo{i} }

// fileInfo implements os.FileInfo and fs.FileInfo for a given FileInfo
type fileInfo struct{ i *FileInfo }
Expand Down
5 changes: 2 additions & 3 deletions filereader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/fs"

"github.com/ungerik/go-fs/fsimpl"
)
Expand Down Expand Up @@ -58,8 +57,8 @@ type FileReader interface {
// WriteTo implements the io.WriterTo interface
WriteTo(writer io.Writer) (n int64, err error)

// OpenReader opens the file and returns a io/fs.File that has to be closed after reading
OpenReader() (fs.File, error)
// OpenReader opens the file and returns a ReadCloser that has to be closed after reading
OpenReader() (ReadCloser, error)

// OpenReadSeeker opens the file and returns a ReadSeekCloser.
// Use OpenReader if seeking is not necessary because implementations
Expand Down
15 changes: 10 additions & 5 deletions filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ package fs
import (
"context"
"io"
"io/fs"
iofs "io/fs"
)

type (
ReadCloser = iofs.File
WriteCloser = io.WriteCloser
)

// FileSystem is an interface that has to be implemented for
Expand Down Expand Up @@ -59,7 +64,7 @@ type FileSystem interface {
// If filePath is the root of the file systeme, then an empty string will be returned for name.
SplitDirAndName(filePath string) (dir, name string)

Stat(filePath string) (fs.FileInfo, error)
Stat(filePath string) (iofs.FileInfo, error)

// IsHidden returns if a file is hidden depending
// on the definition of hidden files of the file system,
Expand Down Expand Up @@ -90,8 +95,8 @@ type FileSystem interface {

MakeDir(dirPath string, perm []Permissions) error

OpenReader(filePath string) (fs.File, error)
OpenWriter(filePath string, perm []Permissions) (io.WriteCloser, error)
OpenReader(filePath string) (ReadCloser, error)
OpenWriter(filePath string, perm []Permissions) (WriteCloser, error)
OpenReadWriter(filePath string, perm []Permissions) (ReadWriteSeekCloser, error)

// Remove deletes the file.
Expand Down Expand Up @@ -218,7 +223,7 @@ type AppendFileSystem interface {
type AppendWriterFileSystem interface {
FileSystem

OpenAppendWriter(filePath string, perm []Permissions) (io.WriteCloser, error)
OpenAppendWriter(filePath string, perm []Permissions) (WriteCloser, error)
}

type TruncateFileSystem interface {
Expand Down
10 changes: 5 additions & 5 deletions fsimpl/direntry.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package fsimpl

import "io/fs"
import iofs "io/fs"

// DirEntryFromFileInfo wraps a io/fs.FileInfo as io/fs.DirEntry.
func DirEntryFromFileInfo(info fs.FileInfo) fs.DirEntry {
func DirEntryFromFileInfo(info iofs.FileInfo) iofs.DirEntry {
return dirEntry{info}
}

type dirEntry struct {
fs.FileInfo
iofs.FileInfo
}

func (dir dirEntry) Type() fs.FileMode { return dir.Mode() }
func (dir dirEntry) Info() (fs.FileInfo, error) { return dir.FileInfo, nil }
func (dir dirEntry) Type() iofs.FileMode { return dir.Mode() }
func (dir dirEntry) Info() (iofs.FileInfo, error) { return dir.FileInfo, nil }
25 changes: 13 additions & 12 deletions fsimpl/filebuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,31 @@ package fsimpl
import (
"errors"
"io"
"io/fs"
iofs "io/fs"
)

var _ fs.File = new(ReadonlyFileBuffer)
var _ iofs.File = new(ReadonlyFileBuffer)

// ReadonlyFileBuffer is a memory buffer that implements ReadSeekCloser which combines the interfaces
// io/fs.File
// io.Reader
// io.ReaderAt
// io.Seeker
// io.Closer
//
// io/fs.File
// io.Reader
// io.ReaderAt
// io.Seeker
// io.Closer
type ReadonlyFileBuffer struct {
info fs.FileInfo
info iofs.FileInfo
data []byte
pos int64 // current reading index
close func() error
}

// NewReadonlyFileBuffer returns a new ReadonlyFileBuffer
func NewReadonlyFileBuffer(data []byte, info fs.FileInfo) *ReadonlyFileBuffer {
func NewReadonlyFileBuffer(data []byte, info iofs.FileInfo) *ReadonlyFileBuffer {
return &ReadonlyFileBuffer{data: data, info: info}
}

func NewReadonlyFileBufferReadAll(reader io.Reader, info fs.FileInfo) (*ReadonlyFileBuffer, error) {
func NewReadonlyFileBufferReadAll(reader io.Reader, info iofs.FileInfo) (*ReadonlyFileBuffer, error) {
data, err := io.ReadAll(reader)
if err != nil {
return nil, err
Expand All @@ -35,11 +36,11 @@ func NewReadonlyFileBufferReadAll(reader io.Reader, info fs.FileInfo) (*Readonly
}

// NewReadonlyFileBufferWithClose returns a new ReadonlyFileBuffer
func NewReadonlyFileBufferWithClose(data []byte, info fs.FileInfo, close func() error) *ReadonlyFileBuffer {
func NewReadonlyFileBufferWithClose(data []byte, info iofs.FileInfo, close func() error) *ReadonlyFileBuffer {
return &ReadonlyFileBuffer{data: data, info: info, close: close}
}

func (buf *ReadonlyFileBuffer) Stat() (fs.FileInfo, error) {
func (buf *ReadonlyFileBuffer) Stat() (iofs.FileInfo, error) {
return buf.info, nil
}

Expand Down
11 changes: 5 additions & 6 deletions invalidfilesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package fs

import (
"context"
"io"
"io/fs"
iofs "io/fs"
"net/url"
"path"
"strings"
Expand Down Expand Up @@ -94,7 +93,7 @@ func (InvalidFileSystem) VolumeName(filePath string) string {
return "invalid:"
}

func (InvalidFileSystem) Stat(filePath string) (fs.FileInfo, error) {
func (InvalidFileSystem) Stat(filePath string) (iofs.FileInfo, error) {
return nil, ErrInvalidFileSystem
}

Expand Down Expand Up @@ -166,15 +165,15 @@ func (InvalidFileSystem) Append(ctx context.Context, filePath string, data []byt
return ErrInvalidFileSystem
}

func (InvalidFileSystem) OpenReader(filePath string) (fs.File, error) {
func (InvalidFileSystem) OpenReader(filePath string) (ReadCloser, error) {
return nil, ErrInvalidFileSystem
}

func (InvalidFileSystem) OpenWriter(filePath string, perm []Permissions) (io.WriteCloser, error) {
func (InvalidFileSystem) OpenWriter(filePath string, perm []Permissions) (WriteCloser, error) {
return nil, ErrInvalidFileSystem
}

func (InvalidFileSystem) OpenAppendWriter(filePath string, perm []Permissions) (io.WriteCloser, error) {
func (InvalidFileSystem) OpenAppendWriter(filePath string, perm []Permissions) (WriteCloser, error) {
return nil, ErrInvalidFileSystem
}

Expand Down
10 changes: 5 additions & 5 deletions localfilesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
iofs "io/fs"
"net/url"
"os"
"os/user"
Expand Down Expand Up @@ -181,7 +181,7 @@ func (local *LocalFileSystem) VolumeName(filePath string) string {
return filepath.VolumeName(filePath)
}

func (local *LocalFileSystem) Stat(filePath string) (fs.FileInfo, error) {
func (local *LocalFileSystem) Stat(filePath string) (iofs.FileInfo, error) {
filePath = expandTilde(filePath)
info, err := os.Stat(filePath)
if err != nil {
Expand Down Expand Up @@ -551,7 +551,7 @@ func (local *LocalFileSystem) Append(ctx context.Context, filePath string, data
return err
}

func (local *LocalFileSystem) OpenReader(filePath string) (fs.File, error) {
func (local *LocalFileSystem) OpenReader(filePath string) (ReadCloser, error) {
if filePath == "" {
return nil, ErrEmptyPath
}
Expand All @@ -560,7 +560,7 @@ func (local *LocalFileSystem) OpenReader(filePath string) (fs.File, error) {
return f, wrapOSErr(filePath, err)
}

func (local *LocalFileSystem) OpenWriter(filePath string, perm []Permissions) (io.WriteCloser, error) {
func (local *LocalFileSystem) OpenWriter(filePath string, perm []Permissions) (WriteCloser, error) {
if filePath == "" {
return nil, ErrEmptyPath
}
Expand All @@ -570,7 +570,7 @@ func (local *LocalFileSystem) OpenWriter(filePath string, perm []Permissions) (i
return f, wrapOSErr(filePath, err)
}

func (local *LocalFileSystem) OpenAppendWriter(filePath string, perm []Permissions) (io.WriteCloser, error) {
func (local *LocalFileSystem) OpenAppendWriter(filePath string, perm []Permissions) (WriteCloser, error) {
if filePath == "" {
return nil, ErrEmptyPath
}
Expand Down
16 changes: 8 additions & 8 deletions memfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"encoding/xml"
"fmt"
"io"
"io/fs"
iofs "io/fs"
"strings"
"time"

Expand Down Expand Up @@ -231,7 +231,7 @@ func (f MemFile) WriteTo(writer io.Writer) (n int64, err error) {
}

// OpenReader opens the file and returns a io/fs.File that has to be closed after reading
func (f MemFile) OpenReader() (fs.File, error) {
func (f MemFile) OpenReader() (ReadCloser, error) {
return fsimpl.NewReadonlyFileBuffer(f.FileData, memFileInfo{f}), nil
}

Expand Down Expand Up @@ -324,11 +324,11 @@ func (f *MemFile) Write(b []byte) (int, error) {
}

// Stat returns a io/fs.FileInfo describing the MemFile.
func (f MemFile) Stat() (fs.FileInfo, error) {
func (f MemFile) Stat() (iofs.FileInfo, error) {
return memFileInfo{f}, nil
}

var _ fs.FileInfo = memFileInfo{}
var _ iofs.FileInfo = memFileInfo{}

// memFileInfo implements io/fs.FileInfo for a MemFile.
//
Expand All @@ -337,7 +337,7 @@ type memFileInfo struct {
MemFile
}

func (i memFileInfo) Mode() fs.FileMode { return 0666 }
func (i memFileInfo) ModTime() time.Time { return time.Now() }
func (i memFileInfo) IsDir() bool { return false }
func (i memFileInfo) Sys() interface{} { return nil }
func (i memFileInfo) Mode() iofs.FileMode { return 0666 }
func (i memFileInfo) ModTime() time.Time { return time.Now() }
func (i memFileInfo) IsDir() bool { return false }
func (i memFileInfo) Sys() interface{} { return nil }
5 changes: 2 additions & 3 deletions memfilesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"io"
iofs "io/fs"
"net/url"
"path"
Expand Down Expand Up @@ -555,11 +554,11 @@ func (fs *MemFileSystem) OpenReader(filePath string) (iofs.File, error) {
return nil, nil
}

func (fs *MemFileSystem) OpenWriter(filePath string, perm []Permissions) (io.WriteCloser, error) {
func (fs *MemFileSystem) OpenWriter(filePath string, perm []Permissions) (WriteCloser, error) {
return nil, nil
}

func (fs *MemFileSystem) OpenAppendWriter(filePath string, perm []Permissions) (io.WriteCloser, error) {
func (fs *MemFileSystem) OpenAppendWriter(filePath string, perm []Permissions) (WriteCloser, error) {
return nil, nil
}

Expand Down
Loading

0 comments on commit e80d166

Please sign in to comment.