Removed all the pointers
This commit is contained in:
+12
-2
@@ -3,6 +3,7 @@ package data
|
||||
import (
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"io/fs"
|
||||
|
||||
"github.com/CalebQ42/squashfs/internal/decompress"
|
||||
)
|
||||
@@ -17,10 +18,11 @@ type Reader struct {
|
||||
curIndex uint64
|
||||
finalBlockSize uint64
|
||||
blockSize uint32
|
||||
closed bool
|
||||
}
|
||||
|
||||
func NewReader(r io.Reader, d decompress.Decompressor, sizes []uint32, finalBlockSize uint64, blockSize uint32) *Reader {
|
||||
return &Reader{
|
||||
func NewReader(r io.Reader, d decompress.Decompressor, sizes []uint32, finalBlockSize uint64, blockSize uint32) Reader {
|
||||
return Reader{
|
||||
r: r,
|
||||
d: d,
|
||||
sizes: sizes,
|
||||
@@ -66,6 +68,9 @@ func (r *Reader) advance() error {
|
||||
}
|
||||
|
||||
func (r *Reader) Read(b []byte) (int, error) {
|
||||
if r.closed {
|
||||
return 0, fs.ErrClosed
|
||||
}
|
||||
curRead := 0
|
||||
var toRead int
|
||||
for curRead < len(b) {
|
||||
@@ -83,6 +88,9 @@ func (r *Reader) Read(b []byte) (int, error) {
|
||||
}
|
||||
|
||||
func (r *Reader) Close() error {
|
||||
r.closed = true
|
||||
r.r = nil
|
||||
r.d = nil
|
||||
if r.frag != nil {
|
||||
if l, ok := r.frag.(*io.LimitedReader); ok {
|
||||
if cl, ok := l.R.(io.Closer); ok {
|
||||
@@ -90,6 +98,8 @@ func (r *Reader) Close() error {
|
||||
}
|
||||
}
|
||||
}
|
||||
r.frag = nil
|
||||
r.sizes = nil
|
||||
r.dat = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user