From 999709fa6ba62ce8a788e490f901f4769d9069c6 Mon Sep 17 00:00:00 2001 From: Wang Qian <1498953301@qq.com> Date: Tue, 21 Nov 2023 16:20:00 +0800 Subject: [PATCH] feat(common): add some common setup. --- adaptive/writer.go | 1 + common/common.go | 5 +++++ compression/zstd/decoder.go | 2 +- compression/zstd/encoder.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- interfaces/common.go | 28 ++++++++++++++++++++++++++++ 7 files changed, 39 insertions(+), 5 deletions(-) diff --git a/adaptive/writer.go b/adaptive/writer.go index f11eda8..997c316 100644 --- a/adaptive/writer.go +++ b/adaptive/writer.go @@ -27,6 +27,7 @@ import ( "github.com/wqshr12345/golib/statistics" ) +// 使用自定义格式+非流式压缩(块式压缩) /* Adaptive Encoding Format: | compress_type(1 byte) | timestamp(8 bytes) | data_length(4 bytes) | (compressed )data(data_length bytes) | diff --git a/common/common.go b/common/common.go index 0518d93..69e2884 100644 --- a/common/common.go +++ b/common/common.go @@ -16,4 +16,9 @@ const ( CompressTypeNone = uint8(0) CompressTypeSnappy = uint8(1) CompressTypeZstd = uint8(2) + CompressTypeGzip = uint8(3) + CompressTypeBzip2 = uint8(4) + CompressTypeFlate = uint8(5) + CompressTypeZlib = uint8(6) + CompressTypeLzw = uint8(7) ) diff --git a/compression/zstd/decoder.go b/compression/zstd/decoder.go index 65ef046..ed67e03 100644 --- a/compression/zstd/decoder.go +++ b/compression/zstd/decoder.go @@ -1,7 +1,7 @@ package zstd import ( - "github.com/klauspost/compress/zstd" + "github.com/wqshr12345/compress/zstd" ) func NewDecompressor() *ZstdDecompressor { diff --git a/compression/zstd/encoder.go b/compression/zstd/encoder.go index 134ee42..28e5158 100644 --- a/compression/zstd/encoder.go +++ b/compression/zstd/encoder.go @@ -1,7 +1,7 @@ package zstd import ( - "github.com/klauspost/compress/zstd" + "github.com/wqshr12345/compress/zstd" ) func NewCompressor() *ZstdCompressor { diff --git a/go.mod b/go.mod index 96d8e43..41c6884 100644 --- a/go.mod +++ b/go.mod @@ -7,10 +7,10 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatedier/kcp-go v2.0.4-0.20190803094908-fe8645b0a904+incompatible github.com/golang/snappy v0.0.4 - github.com/klauspost/compress v1.17.2 github.com/klauspost/reedsolomon v1.9.15 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/stretchr/testify v1.6.1 + github.com/wqshr12345/compress v0.0.2 golang.org/x/crypto v0.4.0 golang.org/x/net v0.7.0 ) diff --git a/go.sum b/go.sum index db5cff8..c89e792 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,6 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= -github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/klauspost/cpuid/v2 v2.0.6 h1:dQ5ueTiftKxp0gyjKSx5+8BtPWkyQbd95m8Gys/RarI= github.com/klauspost/cpuid/v2 v2.0.6/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/reedsolomon v1.9.15 h1:g2erWKD2M6rgnPf89fCji6jNlhMKMdXcuNHMW1SYCIo= @@ -50,6 +48,8 @@ github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b h1:fj5tQ8acgNUr6O8LE github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b/go.mod h1:5XA7W9S6mni3h5uvOC75dA3m9CCCaS83lltmc0ukdi4= github.com/tjfoc/gmsm v1.4.1 h1:aMe1GlZb+0bLjn+cKTPEvvn9oUEBlJitaZiiBwsbgho= github.com/tjfoc/gmsm v1.4.1/go.mod h1:j4INPkHWMrhJb38G+J6W4Tw0AbuN8Thu3PbdVYhVcTE= +github.com/wqshr12345/compress v0.0.2 h1:oRtt6X1qBkEqmIjeDdtbDdRmwT3YBy6iZWaqROOsVuk= +github.com/wqshr12345/compress v0.0.2/go.mod h1:SujRClheOvX5i6T20qVR64mCWOQr34P4UzcAyylad5c= github.com/xtaci/lossyconn v0.0.0-20200209145036-adba10fffc37 h1:EWU6Pktpas0n8lLQwDsRyZfmkPeRbdgPtW609es+/9E= github.com/xtaci/lossyconn v0.0.0-20200209145036-adba10fffc37/go.mod h1:HpMP7DB2CyokmAh4lp0EQnnWhmycP/TvwBGzvuie+H0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/interfaces/common.go b/interfaces/common.go index bb5f86e..b49fb5b 100644 --- a/interfaces/common.go +++ b/interfaces/common.go @@ -19,6 +19,12 @@ type Flusher interface { Flush() error } +type WriteFlushCloser interface { + io.Writer + Flusher + io.Closer +} + type WriteFlusher interface { io.Writer Flusher @@ -44,3 +50,25 @@ type WriterFlusher2 interface { type Reader2 interface { Read2(p []byte) (n int, cmprInfo common.CompressInfo, isNil bool, err error) } + +type MockWriteCloserFlusher struct { + w io.WriteCloser +} + +func NewMockWriteCloserFlusher(w io.WriteCloser) *MockWriteCloserFlusher { + return &MockWriteCloserFlusher{ + w: w, + } +} + +func (m *MockWriteCloserFlusher) Write(p []byte) (n int, err error) { + return m.w.Write(p) +} + +func (m *MockWriteCloserFlusher) Close() error { + return m.w.Close() +} + +func (m *MockWriteCloserFlusher) Flush() error { + return nil +}