Simpler creation of GZIP writer
@@ -68,11 +68,6 @@ func (m *RequestMarshaler) Marshal(r Requester) ([]byte, bool, error) {
stats.Add(numRequests, 0)
compress := false
- gzw, err := gzip.NewWriterLevel(nil, gzip.BestCompression)
- if err != nil {
- panic(fmt.Sprintf("failed to create GZIP writer: %s", err.Error()))
- }
-
stmts := r.GetRequest().GetStatements()
if len(stmts) >= m.BatchThreshold {
compress = true
@@ -95,7 +90,11 @@ func (m *RequestMarshaler) Marshal(r Requester) ([]byte, bool, error) {
if compress {
// Let's try compression.
var buf bytes.Buffer
- gzw.Reset(&buf)
+ gzw, err := gzip.NewWriterLevel(&buf, gzip.BestCompression)
+ if err != nil {
+ return nil, false, fmt.Errorf("gzip new writer: %s", err)
+ }
+
if _, err := gzw.Write(b); err != nil {
return nil, false, fmt.Errorf("gzip Write: %s", err)
}
