From 4c1cf1cdb5181b8e2086984a120544afe92334c2 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Fri, 21 Jan 2022 10:06:07 -0700 Subject: [PATCH] fs: Minor move-around and rename example --- fs.go | 36 ++++++++++++++++++------------------ fs_test.go | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/fs.go b/fs.go index 67e62b3b..274595af 100644 --- a/fs.go +++ b/fs.go @@ -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 { @@ -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. diff --git a/fs_test.go b/fs_test.go index 19c2c297..ab4c85ed 100644 --- a/fs_test.go +++ b/fs_test.go @@ -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{},