Skip to content

Commit

Permalink
s2c/s2sx: Use concurrent decoding (#746)
Browse files Browse the repository at this point in the history
Use concurrent decoding when recompressing and verifying.

s2sx: Use concurrent decoding with single files (non-tar)
  • Loading branch information
klauspost committed Jan 24, 2023
1 parent fe37dc6 commit 69922df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion s2/cmd/_s2sx/_unpack/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func main() {
defer f.Close()
out = f
}
_, err = io.Copy(out, dec)
_, err = dec.DecodeConcurrent(out, 0)
exitErr(err)

case opUnTar:
Expand Down
11 changes: 8 additions & 3 deletions s2/cmd/s2c/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ Options:`)
}
start := time.Now()
dec.Reset(buf)
n, err := io.Copy(io.Discard, dec)
n, err := dec.DecodeConcurrent(io.Discard, *cpu)
exitErr(err)
if int(n) != len(b) {
exitErr(fmt.Errorf("unexpected size, want %d, got %d", len(b), n))
Expand Down Expand Up @@ -478,7 +478,12 @@ Options:`)
}
if *recomp {
dec := s2.NewReader(src)
src = io.NopCloser(dec)
pr, pw := io.Pipe()
go func() {
_, err := dec.DecodeConcurrent(pw, *cpu)
pw.CloseWithError(err)
}()
src = pr
}

var out io.Writer
Expand Down Expand Up @@ -582,7 +587,7 @@ func verifyTo(w io.Writer) (io.Writer, func() error) {
go func() {
defer wg.Done()
r := s2.NewReader(pr)
_, err = io.Copy(io.Discard, r)
_, err = r.DecodeConcurrent(io.Discard, *cpu)
pr.CloseWithError(fmt.Errorf("verify: %w", err))
}()
return writer, func() error {
Expand Down

0 comments on commit 69922df

Please sign in to comment.