This repository was archived by the owner on Jan 18, 2026. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed
Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -162,3 +162,14 @@ func (zstdCodec *ZStandardCodec) Encode(b []byte) []byte {
162162 defer zstdCodec .encoder .Reset (nil )
163163 return zstdCodec .encoder .EncodeAll (b , nil )
164164}
165+
166+ // Close closes the zstandard encoder and decoder, releasing resources.
167+ func (zstdCodec * ZStandardCodec ) Close () error {
168+ if zstdCodec .decoder != nil {
169+ zstdCodec .decoder .Close ()
170+ }
171+ if zstdCodec .encoder != nil {
172+ return zstdCodec .encoder .Close ()
173+ }
174+ return nil
175+ }
Original file line number Diff line number Diff line change @@ -176,6 +176,14 @@ func (d *Decoder) Error() error {
176176 return d .reader .Error
177177}
178178
179+ // Close releases codec resources.
180+ func (d * Decoder ) Close () error {
181+ if c , ok := d .codec .(io.Closer ); ok {
182+ return c .Close ()
183+ }
184+ return nil
185+ }
186+
179187func (d * Decoder ) readBlock () int64 {
180188 _ = d .reader .Peek ()
181189 if errors .Is (d .reader .Error , io .EOF ) {
@@ -496,9 +504,15 @@ func (e *Encoder) Flush() error {
496504 return e .writer .Error
497505}
498506
499- // Close closes the encoder, flushing the writer.
507+ // Close closes the encoder, flushing the writer and releasing codec resources .
500508func (e * Encoder ) Close () error {
501- return e .Flush ()
509+ err := e .Flush ()
510+ if c , ok := e .codec .(io.Closer ); ok {
511+ if cerr := c .Close (); cerr != nil && err == nil {
512+ err = cerr
513+ }
514+ }
515+ return err
502516}
503517
504518func (e * Encoder ) writerBlock () error {
You can’t perform that action at this time.
0 commit comments