Skip to content

Commit

Permalink
Apply sparse file fix to reader
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebQ42 committed Aug 11, 2023
1 parent 87f7533 commit a129b25
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions internal/data/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ type Reader struct {
blockSizes []uint32
blockSize uint32
resetable bool
fileSize uint64
}

func NewReader(r io.Reader, d decompress.Decompressor, blockSizes []uint32, blockSize uint32) *Reader {
func NewReader(r io.Reader, d decompress.Decompressor, blockSizes []uint32, blockSize uint32, fileSize uint64) *Reader {
return &Reader{
d: d,
master: r,
blockSizes: blockSizes,
blockSize: blockSize,
resetable: true,
fileSize: fileSize,
}
}

Expand All @@ -49,7 +51,11 @@ func (r *Reader) advance() (err error) {
} else {
size := realSize(r.blockSizes[0])
if size == 0 {
r.cur = bytes.NewReader(make([]byte, r.blockSize))
outSize := r.blockSize
if r.fileSize < uint64(r.blockSize) {
outSize = uint32(r.fileSize)
}
r.cur = bytes.NewReader(make([]byte, outSize))
} else {
r.cur = io.LimitReader(r.master, int64(size))
if size == r.blockSizes[0] {
Expand Down
2 changes: 1 addition & 1 deletion reader_inode.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (r Reader) getReaders(i inode.Inode) (full *data.FullReader, rdr *data.Read
} else {
return nil, nil, errors.New("getReaders called on non-file type")
}
rdr = data.NewReader(toreader.NewReader(r.r, int64(blockOffset)), r.d, blockSizes, r.s.BlockSize)
rdr = data.NewReader(toreader.NewReader(r.r, int64(blockOffset)), r.d, blockSizes, r.s.BlockSize, fileSize)
full = data.NewFullReader(r.r, uint64(blockOffset), r.d, blockSizes, r.s.BlockSize, fileSize)
if fragInd != 0xFFFFFFFF {
full.AddFragment(func() (io.Reader, error) {
Expand Down

0 comments on commit a129b25

Please sign in to comment.