Documentation!
Though may functions/structs will be made private, I still want things documented.
This commit is contained in:
@@ -6,12 +6,15 @@ import (
|
||||
"io"
|
||||
)
|
||||
|
||||
//Decompressor is a squashfs decompressor interface. Allows for easy decompression no matter the type of compression.
|
||||
type Decompressor interface {
|
||||
Decompress(io.Reader) ([]byte, error)
|
||||
}
|
||||
|
||||
//ZlibDecompressor is a decompressor for gzip type compression
|
||||
type ZlibDecompressor struct{}
|
||||
|
||||
//Decompress reads the entirety of the given reader and returns it uncompressed as a byte slice.
|
||||
func (z *ZlibDecompressor) Decompress(r io.Reader) ([]byte, error) {
|
||||
rdr, err := zlib.NewReader(r)
|
||||
if err != nil {
|
||||
|
||||
@@ -106,6 +106,8 @@ func (d *DataReader) readCurBlock() error {
|
||||
d.curData = make([]byte, d.r.super.BlockSize)
|
||||
d.blocks[d.curBlock].uncompressedSize = d.r.super.BlockSize
|
||||
d.blocks[d.curBlock].begOffset = d.offset
|
||||
fmt.Println("dat red")
|
||||
fmt.Println(len(d.curData))
|
||||
return nil
|
||||
}
|
||||
sec := io.NewSectionReader(d.r.r, d.offset, int64(d.blocks[d.curBlock].size))
|
||||
@@ -118,6 +120,8 @@ func (d *DataReader) readCurBlock() error {
|
||||
d.curData = btys
|
||||
d.blocks[d.curBlock].begOffset = d.offset
|
||||
d.offset += int64(d.blocks[d.curBlock].size)
|
||||
fmt.Println("dat red")
|
||||
fmt.Println(len(d.curData))
|
||||
return nil
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
|
||||
+5
-1
@@ -13,6 +13,7 @@ type metadata struct {
|
||||
compressed bool
|
||||
}
|
||||
|
||||
//MetadataReader is a block reader for metadata. It will automatically read the next block, when it reaches the end of a block.
|
||||
type MetadataReader struct {
|
||||
s *Reader
|
||||
offset int64
|
||||
@@ -21,6 +22,7 @@ type MetadataReader struct {
|
||||
readOffset int
|
||||
}
|
||||
|
||||
//NewMetadataReader creates a new MetadataReader, beginning to read at the given offset. It will automatically cache the first block at the location.
|
||||
func (s *Reader) NewMetadataReader(offset int64) (*MetadataReader, error) {
|
||||
var br MetadataReader
|
||||
br.s = s
|
||||
@@ -36,6 +38,7 @@ func (s *Reader) NewMetadataReader(offset int64) (*MetadataReader, error) {
|
||||
return &br, nil
|
||||
}
|
||||
|
||||
//NewMetadataReaderFromInodeRef creates a new MetadataReader with the offsets set by the given inode reference.
|
||||
func (s *Reader) NewMetadataReaderFromInodeRef(ref uint64) (*MetadataReader, error) {
|
||||
offset, metaOffset := processInodeRef(ref)
|
||||
br, err := s.NewMetadataReader(int64(s.super.InodeTableStart + offset))
|
||||
@@ -88,6 +91,7 @@ func (br *MetadataReader) readNextDataBlock() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//Read reads bytes into the given byte slice. Returns the amount of data read.
|
||||
func (br *MetadataReader) Read(p []byte) (int, error) {
|
||||
if br.readOffset+len(p) < len(br.data) {
|
||||
for i := 0; i < len(p); i++ {
|
||||
@@ -123,7 +127,7 @@ func (br *MetadataReader) Read(p []byte) (int, error) {
|
||||
return read, nil
|
||||
}
|
||||
|
||||
//Seek will seek to the specified location (if possible).
|
||||
//Seek will seek to the specified location (if possible). Seeking is relative to the uncompressed data.
|
||||
//When io.SeekCurrent or io.SeekStart is set, if seeking would put the offset beyond the current cached data, it will try to read the next data blocks to accomodate. On a failure it will seek to the end of the data.
|
||||
//When io.SeekEnd is set, it wil seek reletive to the currently cached data.
|
||||
func (br *MetadataReader) Seek(offset int64, whence int) (int64, error) {
|
||||
|
||||
@@ -129,6 +129,7 @@ func (r *Reader) readDir(i *inode.Inode) (paths []string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
//GetFileStructure returns ALL folders and files contained in the squashfs. Folders end with a "/".
|
||||
func (r *Reader) GetFileStructure() ([]string, error) {
|
||||
in, err := r.GetInodeFromPath("")
|
||||
if err != nil {
|
||||
|
||||
@@ -9,6 +9,7 @@ const (
|
||||
zstdCompression
|
||||
)
|
||||
|
||||
//Superblock contains important information about a squashfs file. Located at the very front of the archive.
|
||||
type Superblock struct {
|
||||
Magic uint32
|
||||
InodeCount uint32
|
||||
@@ -31,6 +32,7 @@ type Superblock struct {
|
||||
ExportTableStart uint64
|
||||
}
|
||||
|
||||
//SuperblockFlags is the parsed version of Superblock.Flags
|
||||
type SuperblockFlags struct {
|
||||
UncompressedInodes bool
|
||||
UncompressedData bool
|
||||
@@ -46,6 +48,7 @@ type SuperblockFlags struct {
|
||||
UncompressedIDs bool
|
||||
}
|
||||
|
||||
//GetFlags returns a SuperblockFlags for a given superblock.
|
||||
func (s *Superblock) GetFlags() SuperblockFlags {
|
||||
return SuperblockFlags{
|
||||
UncompressedInodes: s.Flags&0x1 == 0x1,
|
||||
|
||||
Reference in New Issue
Block a user