fs.go 562 B

123456789101112131415161718192021222324252627282930
  1. package tar2go
  2. import (
  3. "io/fs"
  4. )
  5. var (
  6. _ fs.FS = &filesystem{}
  7. _ fs.File = &file{}
  8. )
  9. type filesystem struct {
  10. idx *Index
  11. }
  12. func (f *filesystem) Open(name string) (fs.File, error) {
  13. idx, err := f.idx.indexWithLock(name)
  14. if err != nil {
  15. return nil, &fs.PathError{Path: name, Op: "open", Err: err}
  16. }
  17. return newFile(idx), nil
  18. }
  19. func (f *filesystem) Stat(name string) (fs.FileInfo, error) {
  20. idx, err := f.idx.indexWithLock(name)
  21. if err != nil {
  22. return nil, &fs.PathError{Path: name, Op: "stat", Err: err}
  23. }
  24. return &fileinfo{h: idx.hdr}, nil
  25. }