|
|
@@ -94,7 +94,9 @@ func (z *Reader) readHeader(first bool) error {
|
|
|
if n := 2 * bSize; cap(z.zdata) < n {
|
|
|
z.zdata = make([]byte, n, n)
|
|
|
}
|
|
|
- debug("header block max size id=%d size=%d", bmsID, bSize)
|
|
|
+ if debugFlag {
|
|
|
+ debug("header block max size id=%d size=%d", bmsID, bSize)
|
|
|
+ }
|
|
|
z.zdata = z.zdata[:bSize]
|
|
|
z.data = z.zdata[:cap(z.zdata)][bSize:]
|
|
|
z.idx = len(z.data)
|
|
|
@@ -121,7 +123,9 @@ func (z *Reader) readHeader(first bool) error {
|
|
|
}
|
|
|
|
|
|
z.Header.done = true
|
|
|
- debug("header read: %v", z.Header)
|
|
|
+ if debugFlag {
|
|
|
+ debug("header read: %v", z.Header)
|
|
|
+ }
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
@@ -132,13 +136,17 @@ func (z *Reader) readHeader(first bool) error {
|
|
|
// change between calls to Read(). If that is the case, no data is actually read from
|
|
|
// the underlying io.Reader, to allow for potential input buffer resizing.
|
|
|
func (z *Reader) Read(buf []byte) (int, error) {
|
|
|
- debug("Read buf len=%d", len(buf))
|
|
|
+ if debugFlag {
|
|
|
+ debug("Read buf len=%d", len(buf))
|
|
|
+ }
|
|
|
if !z.Header.done {
|
|
|
if err := z.readHeader(true); err != nil {
|
|
|
return 0, err
|
|
|
}
|
|
|
- debug("header read OK compressed buffer %d / %d uncompressed buffer %d : %d index=%d",
|
|
|
- len(z.zdata), cap(z.zdata), len(z.data), cap(z.data), z.idx)
|
|
|
+ if debugFlag {
|
|
|
+ debug("header read OK compressed buffer %d / %d uncompressed buffer %d : %d index=%d",
|
|
|
+ len(z.zdata), cap(z.zdata), len(z.data), cap(z.data), z.idx)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if len(buf) == 0 {
|
|
|
@@ -147,7 +155,9 @@ func (z *Reader) Read(buf []byte) (int, error) {
|
|
|
|
|
|
if z.idx == len(z.data) {
|
|
|
// No data ready for reading, process the next block.
|
|
|
- debug("reading block from writer")
|
|
|
+ if debugFlag {
|
|
|
+ debug("reading block from writer")
|
|
|
+ }
|
|
|
// Block length: 0 = end of frame, highest bit set: uncompressed.
|
|
|
bLen, err := z.readUint32()
|
|
|
if err != nil {
|
|
|
@@ -163,7 +173,9 @@ func (z *Reader) Read(buf []byte) (int, error) {
|
|
|
if err != nil {
|
|
|
return 0, err
|
|
|
}
|
|
|
- debug("frame checksum got=%x / want=%x", z.checksum.Sum32(), checksum)
|
|
|
+ if debugFlag {
|
|
|
+ debug("frame checksum got=%x / want=%x", z.checksum.Sum32(), checksum)
|
|
|
+ }
|
|
|
z.pos += 4
|
|
|
if h := z.checksum.Sum32(); checksum != h {
|
|
|
return 0, fmt.Errorf("lz4: invalid frame checksum: got %x; expected %x", h, checksum)
|
|
|
@@ -179,11 +191,15 @@ func (z *Reader) Read(buf []byte) (int, error) {
|
|
|
return 0, z.readHeader(false)
|
|
|
}
|
|
|
|
|
|
- debug("raw block size %d", bLen)
|
|
|
+ if debugFlag {
|
|
|
+ debug("raw block size %d", bLen)
|
|
|
+ }
|
|
|
if bLen&compressedBlockFlag > 0 {
|
|
|
// Uncompressed block.
|
|
|
bLen &= compressedBlockMask
|
|
|
- debug("uncompressed block size %d", bLen)
|
|
|
+ if debugFlag {
|
|
|
+ debug("uncompressed block size %d", bLen)
|
|
|
+ }
|
|
|
if int(bLen) > cap(z.data) {
|
|
|
return 0, fmt.Errorf("lz4: invalid block size: %d", bLen)
|
|
|
}
|
|
|
@@ -207,7 +223,9 @@ func (z *Reader) Read(buf []byte) (int, error) {
|
|
|
|
|
|
} else {
|
|
|
// Compressed block.
|
|
|
- debug("compressed block size %d", bLen)
|
|
|
+ if debugFlag {
|
|
|
+ debug("compressed block size %d", bLen)
|
|
|
+ }
|
|
|
if int(bLen) > cap(z.data) {
|
|
|
return 0, fmt.Errorf("lz4: invalid block size: %d", bLen)
|
|
|
}
|
|
|
@@ -238,14 +256,18 @@ func (z *Reader) Read(buf []byte) (int, error) {
|
|
|
|
|
|
if !z.NoChecksum {
|
|
|
z.checksum.Write(z.data)
|
|
|
- debug("current frame checksum %x", z.checksum.Sum32())
|
|
|
+ if debugFlag {
|
|
|
+ debug("current frame checksum %x", z.checksum.Sum32())
|
|
|
+ }
|
|
|
}
|
|
|
z.idx = 0
|
|
|
}
|
|
|
|
|
|
n := copy(buf, z.data[z.idx:])
|
|
|
z.idx += n
|
|
|
- debug("copied %d bytes to input", n)
|
|
|
+ if debugFlag {
|
|
|
+ debug("copied %d bytes to input", n)
|
|
|
+ }
|
|
|
|
|
|
return n, nil
|
|
|
}
|