Skip to content

Commit

Permalink
[legacy] Writer: fix #156
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrec committed Feb 12, 2022
1 parent f9f4ce2 commit bc1239b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion internal/lz4block/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ const (
Block256Kb
Block1Mb
Block4Mb
Block8Mb = 2 * Block4Mb
)

// In legacy mode all blocks are compressed regardless
// of the compressed size: use the bound size.
var Block8Mb = uint32(CompressBlockBound(8 << 20))

var (
BlockPool64K = sync.Pool{New: func() interface{} { return make([]byte, Block64Kb) }}
BlockPool256K = sync.Pool{New: func() interface{} { return make([]byte, Block256Kb) }}
Expand Down
4 changes: 3 additions & 1 deletion internal/lz4stream/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ func (b *FrameDataBlock) Close(f *Frame) {
func (b *FrameDataBlock) Compress(f *Frame, src []byte, level lz4block.CompressionLevel) *FrameDataBlock {
data := b.data
if f.isLegacy() {
data = data[:cap(data)]
// In legacy mode, the buffer is sized according to CompressBlockBound,
// but only 8Mb is buffered for compression.
src = src[:8<<20]
} else {
data = data[:len(src)] // trigger the incompressible flag in CompressBlock
}
Expand Down

0 comments on commit bc1239b

Please sign in to comment.