Skip to content

Add fpc compression and decompression mutators #850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ require (
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rs/xid v1.6.0 // indirect
github.com/spenczar/fpc v1.0.0 // indirect
github.com/xanzy/go-gitlab v0.115.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/detectors/gcp v1.29.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
github.com/smartystreets/gunit v1.4.2 h1:tyWYZffdPhQPfK5VsMQXfauwnJkqg7Tv5DLuQVYxq3Q=
github.com/smartystreets/gunit v1.4.2/go.mod h1:ZjM1ozSIMJlAz/ay4SG8PeKF00ckUp+zMHZXV9/bvak=
github.com/spenczar/fpc v1.0.0 h1:H0NtafmaWbJhSghiU5oilPzh/5kdbtQ8nTBt9I4dLMA=
github.com/spenczar/fpc v1.0.0/go.mod h1:14BNj23NWSW7Hf2jk29+fpk9ufQKUGMCefCj9vgjwBU=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
32 changes: 32 additions & 0 deletions pkg/mutators/single/fpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package mutators

import (
"io"

"github.com/spenczar/fpc"
)

func init() {
singleRegister("fpc", wfpc, withDescription("compress 64bit floats"),
withCategory("specific compress"),
)
singleRegister("unfpc", rfpc, withDescription("decompress 64bit floats"),
withCategory("specific decompress"),
)
}

func wfpc(out io.WriteCloser, in io.ReadCloser, _ any) (int64, error) {
f := fpc.NewWriter(out)

// the buffer must obviously be a multiple of 8
n, err := io.CopyBuffer(f, in, make([]byte, 8*1024))
if err != nil {
return n, err
}
err = f.Close()
return n, err
}

func rfpc(out io.WriteCloser, in io.ReadCloser, _ any) (int64, error) {
return io.Copy(out, fpc.NewReader(in))
}
Loading