Skip to content

Commit

Permalink
fs: Minor move-around and rename example
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed Jan 21, 2022
1 parent 2bc852c commit 4c1cf1c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
36 changes: 18 additions & 18 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,6 @@ func (f FileFS) Open(name string) (fs.File, error) {
return compressedFile{file, r}, nil
}

// compressedFile is an fs.File that specially reads
// from a decompression reader, and which closes both
// that reader and the underlying file.
type compressedFile struct {
*os.File
decomp io.ReadCloser
}

func (cf compressedFile) Read(p []byte) (int, error) { return cf.decomp.Read(p) }
func (cf compressedFile) Close() error {
err := cf.File.Close()
err2 := cf.decomp.Close()
if err2 != nil && err == nil {
err = err2
}
return err
}

// ReadDir returns a directory listing with the file as the singular entry.
func (f FileFS) ReadDir(name string) ([]fs.DirEntry, error) {
if err := f.checkName(name, "stat"); err != nil {
Expand Down Expand Up @@ -202,6 +184,24 @@ func (f FileFS) checkName(name, op string) error {
return nil
}

// compressedFile is an fs.File that specially reads
// from a decompression reader, and which closes both
// that reader and the underlying file.
type compressedFile struct {
*os.File
decomp io.ReadCloser
}

func (cf compressedFile) Read(p []byte) (int, error) { return cf.decomp.Read(p) }
func (cf compressedFile) Close() error {
err := cf.File.Close()
err2 := cf.decomp.Close()
if err2 != nil && err == nil {
err = err2
}
return err
}

// ArchiveFS allows accessing an archive (or a compressed archive) using a
// consistent file system interface. Essentially, it allows traversal and
// reading of archive contents the same way as any normal directory on disk.
Expand Down
2 changes: 1 addition & 1 deletion fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestPathWithoutTopDir(t *testing.T) {
//go:embed testdata/test.zip
var testZIP []byte

func ExampleEmbed() {
func ExampleArchiveFS_Stream() {
fsys := ArchiveFS{
Stream: io.NewSectionReader(bytes.NewReader(testZIP), 0, int64(len(testZIP))),
Format: Zip{},
Expand Down

0 comments on commit 4c1cf1c

Please sign in to comment.