Skip to content

Commit

Permalink
feat(common): add some common setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
wqshr12345 committed Nov 21, 2023
1 parent 8a039f2 commit 999709f
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions adaptive/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
5 changes: 5 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
2 changes: 1 addition & 1 deletion compression/zstd/decoder.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package zstd

import (
"github.com/klauspost/compress/zstd"
"github.com/wqshr12345/compress/zstd"
)

func NewDecompressor() *ZstdDecompressor {
Expand Down
2 changes: 1 addition & 1 deletion compression/zstd/encoder.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package zstd

import (
"github.com/klauspost/compress/zstd"
"github.com/wqshr12345/compress/zstd"
)

func NewCompressor() *ZstdCompressor {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down
28 changes: 28 additions & 0 deletions interfaces/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ type Flusher interface {
Flush() error
}

type WriteFlushCloser interface {
io.Writer
Flusher
io.Closer
}

type WriteFlusher interface {
io.Writer
Flusher
Expand All @@ -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
}

0 comments on commit 999709f

Please sign in to comment.