Skip to content

Commit

Permalink
uploader: propagate errors in compress (go-graphite#137)
Browse files Browse the repository at this point in the history
Co-authored-by: Tadeusz Dudkiewicz <[email protected]>
  • Loading branch information
teqwve and teqwve authored Feb 7, 2024
1 parent 3f4e51e commit 898a7d7
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions uploader/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,33 @@ func (u *Base) uploadWorker(ctx context.Context) {
}
}

func compress(data io.Reader) io.Reader {
func compress(data *io.PipeReader) io.Reader {
pr, pw := io.Pipe()
gw := gzip.NewWriter(pw)

go func() {
_, _ = io.Copy(gw, data)
gw.Close()
_, err := io.Copy(gw, data)
if err != nil {
pw.CloseWithError(err)
data.CloseWithError(err)
return
}

err = gw.Close()
if err != nil {
pw.CloseWithError(err)
data.CloseWithError(err)
return
}

pw.Close()
data.Close()
}()

return pr
}

func (u *Base) insertRowBinary(table string, data io.Reader) error {
func (u *Base) insertRowBinary(table string, data *io.PipeReader) error {
p, err := url.Parse(u.config.URL)
if err != nil {
return err
Expand Down

0 comments on commit 898a7d7

Please sign in to comment.