Skip to content

Commit

Permalink
error check
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Dec 14, 2024
1 parent d58a709 commit 994cd82
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func zCompress(src []byte, dst io.Writer) error {
if _, err := zw.Write(src); err != nil {
return err
}
zw.Close()
err := zw.Close()
zwPool.Put(zw)
return nil
return err
}

type compIO struct {
Expand Down Expand Up @@ -168,10 +168,13 @@ func (c *compIO) writePackets(packets []byte) (int, error) {
buf.Write(payload)
uncompressedLen = 0
} else {
zCompress(payload, buf)
err := zCompress(payload, buf)
if debug && err != nil {
fmt.Printf("zCompress error: %v", err)
}
// do not compress if compressed data is larger than uncompressed data
// I intentionally miss 7 byte header in the buf; compress more than 7 bytes.
if buf.Len() >= uncompressedLen {
// I intentionally miss 7 byte header in the buf; zCompress must compress more than 7 bytes.
if err != nil || buf.Len() >= uncompressedLen {
buf.Reset()
buf.Write(blankHeader)
buf.Write(payload)
Expand Down

0 comments on commit 994cd82

Please sign in to comment.