Skip to content

Commit

Permalink
feat(middleware/gzip_utils): Add progress bar to Gzip middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejsika committed Oct 2, 2021
1 parent 9af949f commit aa006a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion backup/middleware/gzip/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package gzip

import (
"io"
"os"

"github.com/cheggaaa/pb/v3"
"github.com/sikalabs/tergum/utils/gzip_utils"
)

Expand All @@ -13,5 +15,17 @@ func (m GzipMiddleware) Validate() error {
}

func (m GzipMiddleware) Process(data io.ReadSeeker) (io.ReadSeeker, error) {
return gzip_utils.GzipIO(data)
var err error

size, _ := data.Seek(0, os.SEEK_END)
data.Seek(0, 0)

bar := pb.Full.Start64(size)

// create proxy reader
barReader := bar.NewProxyReader(data)
out, err := gzip_utils.GzipIO(barReader)
bar.Finish()

return out, err
}
2 changes: 1 addition & 1 deletion utils/gzip_utils/gzip_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func GzipBytes(data []byte) ([]byte, error) {
return b.Bytes(), nil
}

func GzipIO(src io.ReadSeeker) (io.ReadSeeker, error) {
func GzipIO(src io.Reader) (io.ReadSeeker, error) {
var err error

outputFile, err := os.CreateTemp("", "tergum-gzip-")
Expand Down

0 comments on commit aa006a6

Please sign in to comment.