43 lines
823 B
Go
43 lines
823 B
Go
|
package zim
|
||
|
|
||
|
import (
|
||
|
"io"
|
||
|
|
||
|
"github.com/pkg/errors"
|
||
|
"github.com/ulikunitz/xz"
|
||
|
)
|
||
|
|
||
|
type XZBlobReader struct {
|
||
|
decoder *xz.Reader
|
||
|
}
|
||
|
|
||
|
// Close implements io.ReadCloser.
|
||
|
func (r *XZBlobReader) Close() error {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// Read implements io.ReadCloser.
|
||
|
func (r *XZBlobReader) Read(p []byte) (n int, err error) {
|
||
|
return r.decoder.Read(p)
|
||
|
}
|
||
|
|
||
|
var _ io.ReadCloser = &XZBlobReader{}
|
||
|
|
||
|
func NewXZBlobReader(reader *Reader, clusterStartOffset, clusterEndOffset uint64, blobIndex uint32, blobSize int) *CompressedBlobReader {
|
||
|
return NewCompressedBlobReader(
|
||
|
reader,
|
||
|
func(r io.Reader) (io.ReadCloser, error) {
|
||
|
decoder, err := xz.NewReader(r)
|
||
|
if err != nil {
|
||
|
return nil, errors.WithStack(err)
|
||
|
}
|
||
|
|
||
|
return &XZBlobReader{decoder}, nil
|
||
|
},
|
||
|
clusterStartOffset,
|
||
|
clusterEndOffset,
|
||
|
blobIndex,
|
||
|
blobSize,
|
||
|
)
|
||
|
}
|