refactor: move request-compression out of codegen, avoid some buffering (#118)

This commit is contained in:
Daniel Moran
2021-06-11 16:01:34 -04:00
committed by GitHub
parent a1f8e0edf1
commit b1ba53bae2
8 changed files with 202 additions and 149 deletions

View File

@ -1,6 +1,8 @@
package write
import (
"bytes"
"compress/gzip"
"context"
"errors"
"fmt"
@ -57,7 +59,15 @@ func (c Client) Write(ctx context.Context, params *Params) error {
}
writeBatch := func(batch []byte) error {
req := c.PostWrite(ctx).Body(batch).ContentEncoding("gzip").Precision(params.Precision)
buf := bytes.Buffer{}
gzw := gzip.NewWriter(&buf)
_, err := gzw.Write(batch)
gzw.Close()
if err != nil {
return err
}
req := c.PostWrite(ctx).Body(buf.Bytes()).ContentEncoding("gzip").Precision(params.Precision)
if params.BucketID != "" {
req = req.Bucket(params.BucketID)
} else {