Skip to content

Commit

Permalink
Change default zstd compressor options to make them more stable over …
Browse files Browse the repository at this point in the history
…time
  • Loading branch information
tomekjarosik committed Nov 2, 2024
1 parent 24b2d2f commit 34629a9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/zstd/zstd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ func ReadCloserLevel(r io.ReadCloser, level int) io.ReadCloser {
go func() error {
// TODO(go1.14): Just defer {pw,zw,r}.Close like you'd expect.
// Context: https://golang.org/issue/24283
zw, err := zstd.NewWriter(bw, zstd.WithEncoderLevel(zstd.EncoderLevelFromZstd(level)))
zw, err := zstd.NewWriter(bw,
zstd.WithEncoderLevel(zstd.EncoderLevelFromZstd(level)),
zstd.WithEncoderConcurrency(1),
zstd.WithZeroFrames(true),
)
if err != nil {
return pw.CloseWithError(err)
}

if _, err := io.Copy(zw, r); err != nil {
buf := make([]byte, 64*1024)
if _, err := io.CopyBuffer(zw, r, buf); err != nil {
defer r.Close()
defer zw.Close()
return pw.CloseWithError(err)
Expand Down

0 comments on commit 34629a9

Please sign in to comment.