Re-wrote a bunch to try to figure out why things weren't working.

Turned out I was reading if a block was compressed exactly opposite.
Started to work more on looking up dirs.
This commit is contained in:
Caleb Gardner
2020-11-16 14:56:19 -06:00
parent 06b188d53c
commit 7a2f9a87ba
25 changed files with 504 additions and 3363 deletions
+39
View File
@@ -0,0 +1,39 @@
package squashfs
import (
"bytes"
"compress/zlib"
"io"
)
type Decompressor interface {
Decompress(io.Reader) ([]byte, error)
DecompressCopy(*io.Writer, *io.SectionReader) error
}
type ZlibDecompressor struct{}
func (z *ZlibDecompressor) Decompress(r io.Reader) ([]byte, error) {
rdr, err := zlib.NewReader(r)
if err != nil {
return nil, err
}
var data bytes.Buffer
_, err = io.Copy(&data, rdr)
if err != nil {
return nil, err
}
return data.Bytes(), nil
}
func (z *ZlibDecompressor) DecompressCopy(w *io.Writer, r *io.SectionReader) error {
rdr, err := zlib.NewReader(r)
if err != nil {
return err
}
_, err = io.Copy(*w, rdr)
if err != nil {
return err
}
return err
}