github.com/TeaOSLab/EdgeNode@v1.3.8/internal/compressions/reader_zstd.go (about) 1 // Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. 2 3 package compressions 4 5 import ( 6 "github.com/klauspost/compress/zstd" 7 "io" 8 ) 9 10 type ZSTDReader struct { 11 BaseReader 12 13 reader *zstd.Decoder 14 } 15 16 func NewZSTDReader(reader io.Reader) (Reader, error) { 17 return sharedZSTDReaderPool.Get(reader) 18 } 19 20 func newZSTDReader(reader io.Reader) (Reader, error) { 21 r, err := zstd.NewReader(reader, zstd.WithDecoderMaxWindow(256<<20)) 22 if err != nil { 23 return nil, err 24 } 25 return &ZSTDReader{ 26 reader: r, 27 }, nil 28 } 29 30 func (this *ZSTDReader) Read(p []byte) (n int, err error) { 31 return this.reader.Read(p) 32 } 33 34 func (this *ZSTDReader) Reset(reader io.Reader) error { 35 return this.reader.Reset(reader) 36 } 37 38 func (this *ZSTDReader) RawClose() error { 39 this.reader.Close() 40 return nil 41 } 42 43 func (this *ZSTDReader) Close() error { 44 return this.Finish(this) 45 }