More setup for Files.
This commit is contained in:
@@ -21,9 +21,9 @@ Thanks also to [distri's squashfs library](https://github.com/distr1/distri/tree
|
|||||||
|
|
||||||
# Not Working (Yet). Not necessarily in order.
|
# Not Working (Yet). Not necessarily in order.
|
||||||
|
|
||||||
* Rename repo so it's easier to import
|
|
||||||
* Provide an easy interface to find and list files and their properties
|
* Provide an easy interface to find and list files and their properties
|
||||||
* Maybe squashfs.File
|
* Maybe squashfs.File
|
||||||
|
* Make device, socket, symlink, and all extended types of inode work properly. (I need to find an archive that uses it first.)
|
||||||
* Extracting files
|
* Extracting files
|
||||||
* from inodes.
|
* from inodes.
|
||||||
* from file info.
|
* from file info.
|
||||||
@@ -41,4 +41,4 @@ Thanks also to [distri's squashfs library](https://github.com/distr1/distri/tree
|
|||||||
|
|
||||||
# Where I'm at
|
# Where I'm at
|
||||||
|
|
||||||
* v0.1 is the first working version!
|
* Working on the File interface that should make it easier to deal with squashfs files. I'm also trying to make them capable for when I get squashing working.
|
||||||
@@ -1,24 +1,55 @@
|
|||||||
package squashfs
|
package squashfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/CalebQ42/squashfs/internal/directory"
|
|
||||||
"github.com/CalebQ42/squashfs/internal/inode"
|
"github.com/CalebQ42/squashfs/internal/inode"
|
||||||
)
|
)
|
||||||
|
|
||||||
//File represents a file within a squashfs. File can be either a file or folder.
|
var (
|
||||||
|
//ErrNotDirectory is returned when you're trying to do directory things with a non-directory
|
||||||
|
ErrNotDirectory = errors.New("File is not a directory")
|
||||||
|
)
|
||||||
|
|
||||||
|
//File is the main way to interact with files within squashfs, or when putting files into a squashfs.
|
||||||
|
//File can be either a file or folder. When reading from a squashfs, it reads from the datablocks.
|
||||||
|
//When writing, this holds the information on WHERE the file will be placed inside the archive.
|
||||||
type File struct {
|
type File struct {
|
||||||
Name string
|
Name string //The name of the file or folder.
|
||||||
Parent *File
|
Parent *File //The parent directory. If it's the root directory, will be nil
|
||||||
Reader *io.Reader
|
Reader io.Reader //Underlying reader. When writing, will probably be an os.File. When reading will probably be a FileReader
|
||||||
path string
|
path string //When writing, you can set where a file goes in the archive with this. (not yet tho)
|
||||||
size uint32
|
size int //The size of the file. -1 if a directory
|
||||||
r *Reader
|
r *Reader //The squashfs.Reader where this file is contained.
|
||||||
in *inode.Inode
|
in *inode.Inode //Underlyting inode when reading.
|
||||||
|
filType int //The file's type, using inode types.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) newFileFromEntry(en *directory.Entry) (f *File, err error) {
|
func (f *File) GetChildren() ([]*File, error) {
|
||||||
f.Name = en.Name
|
if !f.IsDir() {
|
||||||
f.in, err = r.getInodeFromEntry(en)
|
return nil, ErrNotDirectory
|
||||||
|
}
|
||||||
|
//TODO
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
//IsDir returns if the file is a directory.
|
||||||
|
func (f *File) IsDir() bool {
|
||||||
|
return f.filType == inode.BasicDirectoryType || f.filType == inode.ExtDirType
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
func (f *File) Close() {
|
||||||
|
//nil the reader to free up resources (in theory). Might switch reader to be a readcloser to make it easier.
|
||||||
|
f.Reader = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
//Read from the file. Doesn't do anything fancy, just pases it to the underlying io.Reader. If a directory, return io.EOF
|
||||||
|
func (f *File) Read(p []byte) (int, error) {
|
||||||
|
if f.IsDir() {
|
||||||
|
return 0, io.EOF
|
||||||
|
}
|
||||||
|
//Check if reader is nill and create a new one if needed.
|
||||||
|
return f.Reader.Read(p)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user