Finished. Now for bug fixes

This commit is contained in:
Caleb Gardner
2023-12-24 18:20:05 -06:00
parent 5de59627df
commit d9132ab6a4
6 changed files with 385 additions and 20 deletions
+39 -16
View File
@@ -91,13 +91,20 @@ func (f *FS) Open(name string) (fs.File, error) {
}
}
if name == "." || name == "" {
return &File{
b: &f.d.Base,
r: f.r,
parent: f.parent,
}, nil
return f.File(), nil
}
split := strings.Split(name, "/")
if split[0] == ".." {
if f.parent == nil { // root directory
return nil, &fs.PathError{
Op: "open",
Path: name,
Err: fs.ErrNotExist,
}
}
} else {
return f.parent.Open(strings.Join(split[1:], "/"))
}
i, found := slices.BinarySearchFunc(f.d.Entries, split[0], func(e directory.Entry, name string) int {
return strings.Compare(e.Name, name)
})
@@ -116,7 +123,7 @@ func (f *FS) Open(name string) (fs.File, error) {
return &File{
b: b,
r: f.r,
parent: f.parent,
parent: f,
}, nil
}
if !b.IsDir() {
@@ -149,11 +156,7 @@ func (f *FS) ReadDir(name string) ([]fs.DirEntry, error) {
}
}
if name == "." || name == "" {
return (&File{
b: &f.d.Base,
parent: f.parent,
r: f.r,
}).ReadDir(-1)
return f.File().ReadDir(-1)
}
fil, err := f.Open(name)
if err != nil {
@@ -196,11 +199,7 @@ func (f *FS) Stat(name string) (fs.FileInfo, error) {
}
}
if name == "." || name == "" {
return (&File{
b: &f.d.Base,
parent: f.parent,
r: f.r,
}).Stat()
return f.File().Stat()
}
fil, err := f.Open(name)
if err != nil {
@@ -236,6 +235,30 @@ func (f *FS) Sub(dir string) (fs.FS, error) {
return fil.(*File).FS()
}
// Extract the FS to the given folder. If the file is a folder, the folder's contents will be extracted to the folder.
// Uses default extraction options.
func (f *FS) Extract(folder string) error {
return f.File().Extract(folder)
}
// Extract the FS to the given folder. If the file is a folder, the folder's contents will be extracted to the folder.
// Allows setting various extraction options via ExtractionOptions.
func (f *FS) ExtractWithOptions(folder string, op *ExtractionOptions) error {
return f.File().ExtractWithOptions(folder, op)
}
// Returns the FS as a *File
func (f *FS) File() *File {
return &File{
b: &f.d.Base,
parent: f.parent,
r: f.r,
}
}
func (f *FS) path() string {
if f.parent == nil {
return f.d.Name
}
return filepath.Join(f.parent.path(), f.d.Name)
}