more work on decompression
This commit is contained in:
+78
-6
@@ -1,6 +1,9 @@
|
||||
package squashfs
|
||||
|
||||
import "io"
|
||||
import (
|
||||
"compress/zlib"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
zlibCompression = 1 + iota
|
||||
@@ -13,10 +16,10 @@ const (
|
||||
|
||||
//TODO: implement decompress for each type of Options
|
||||
type CompressionOptions interface {
|
||||
Decompress([]byte) []byte
|
||||
DecompressCopy(*io.Reader, *io.Writer)
|
||||
Compress([]byte) []byte
|
||||
CompressCopy(*io.Reader, *io.Writer)
|
||||
Decompress(*io.SectionReader, int) ([]byte, error)
|
||||
DecompressCopy(*io.Reader, *io.Writer) (int, error)
|
||||
Compress(*io.SectionReader, int) ([]byte, error)
|
||||
CompressCopy(*io.Reader, *io.Writer) (int, error)
|
||||
}
|
||||
|
||||
//TODO: Allow creation of options for compression.
|
||||
@@ -29,7 +32,7 @@ type gzipOptionsRaw struct {
|
||||
|
||||
//GzipOptions is the options used for gzip compression. Backed by the raw format, with strategies parsed.
|
||||
type GzipOptions struct {
|
||||
CompressionOptions
|
||||
CompressionOptions //TODO: remove
|
||||
raw *gzipOptionsRaw
|
||||
DefaultStrategy bool
|
||||
FilteredStrategy bool
|
||||
@@ -45,11 +48,80 @@ func NewGzipOptions(raw gzipOptionsRaw) GzipOptions {
|
||||
}
|
||||
}
|
||||
|
||||
func (gzipOp *GzipOptions) Decompress(rdr *io.SectionReader, blockSize int) ([]byte, error) {
|
||||
zlibRdr, err := zlib.NewReader(rdr)
|
||||
defer zlibRdr.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]byte, 0)
|
||||
var tmp []byte
|
||||
read := blockSize
|
||||
for read == blockSize {
|
||||
tmp = make([]byte, blockSize)
|
||||
read, err = zlibRdr.Read(tmp)
|
||||
if err != io.EOF {
|
||||
return nil, err
|
||||
}
|
||||
if read < blockSize {
|
||||
tmp = tmp[:read]
|
||||
}
|
||||
out = append(out, tmp...)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (gzipOp *GzipOptions) DecompressCopy(rdr *io.Reader, wrt *io.Writer) (int, error) {
|
||||
zlibRdr, err := zlib.NewReader(*rdr)
|
||||
defer zlibRdr.Close()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
n, err := io.Copy(*wrt, zlibRdr)
|
||||
return int(n), err
|
||||
}
|
||||
|
||||
func (gzipOp *GzipOptions) Compress(rdr *io.SectionReader, blockSize int) ([]byte, error) {
|
||||
|
||||
}
|
||||
|
||||
func (gzipOp *GzipOptions) CompressCopy(rdr *io.Reader, wrt *io.Writer) (int, error) {
|
||||
zlibWrt, err := zlib.NewWriter(*wrt) //TODO: allow setting level
|
||||
defer zlibWrt.Close()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type xzOptionsRaw struct {
|
||||
dictionarySize int32
|
||||
executableFilters int32
|
||||
}
|
||||
|
||||
type XzOptions struct {
|
||||
CompressionOptions //TODO: Remove
|
||||
raw *xzOptionsRaw
|
||||
Execx86 bool
|
||||
ExecPower bool
|
||||
Execa64 bool
|
||||
ExecArm bool
|
||||
ExecArmThumb bool
|
||||
ExecSparc bool
|
||||
}
|
||||
|
||||
func NewXzOption(raw xzOptionsRaw) XzOptions {
|
||||
return XzOptions{
|
||||
raw: &raw,
|
||||
Execx86: raw.executableFilters&0x1 == 0x1,
|
||||
ExecPower: raw.executableFilters&0x2 == 0x2,
|
||||
Execa64: raw.executableFilters&0x4 == 0x4,
|
||||
ExecArm: raw.executableFilters&0x8 == 0x8,
|
||||
ExecArmThumb: raw.executableFilters&0x10 == 0x10,
|
||||
ExecSparc: raw.executableFilters&0x20 == 0x20,
|
||||
}
|
||||
}
|
||||
|
||||
type lz4OptionsRaw struct {
|
||||
version int32
|
||||
flags int32
|
||||
|
||||
Reference in New Issue
Block a user