-
Notifications
You must be signed in to change notification settings - Fork 491
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: gzip data that is sent to influxdb
- Loading branch information
Showing
4 changed files
with
149 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package influxdb | ||
|
||
import ( | ||
"compress/gzip" | ||
"io" | ||
) | ||
|
||
// CompressWithGzip takes an io.Reader as input and pipes | ||
// it through a gzip.Writer returning an io.Reader containing | ||
// the gzipped data. | ||
// An error is returned if passing data to the gzip.Writer fails | ||
// this is shamelessly stolen from https://github.com/influxdata/telegraf | ||
func CompressWithGzip(data io.Reader, level int) (io.Reader, error) { | ||
pipeReader, pipeWriter := io.Pipe() | ||
gzipWriter, err := gzip.NewWriterLevel(pipeWriter, level) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
go func() { | ||
_, err := io.Copy(gzipWriter, data) | ||
gzipWriter.Close() | ||
// subsequent reads from the read half of the pipe will | ||
// return no bytes and the error err, or EOF if err is nil. | ||
pipeWriter.CloseWithError(err) | ||
}() | ||
|
||
return pipeReader, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters