Skip to content

Commit 55477cb

Browse files
committed
allow concurrency to be specified
1 parent f6a0ebd commit 55477cb

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

cli.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
type CLI struct {
1111
ArchivePath string
1212
Files []string
13+
Concurrency int
1314
}
1415

1516
func (c *CLI) Archive() error {
@@ -19,7 +20,7 @@ func (c *CLI) Archive() error {
1920
}
2021
defer archive.Close()
2122

22-
archiver, err := NewArchiver(archive)
23+
archiver, err := NewArchiver(archive, Concurrency(c.Concurrency))
2324
if err != nil {
2425
return errors.Wrap(err, "ERROR: could not create archiver")
2526
}

cli_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package pzip_test
33
import (
44
"os"
55
"path/filepath"
6+
"runtime"
67
"testing"
78

89
"github.com/alecthomas/assert/v2"
@@ -18,7 +19,7 @@ func TestCLI(t *testing.T) {
1819
archivePath := "testdata/archive.zip"
1920
defer os.RemoveAll(archivePath)
2021

21-
cli := pzip.CLI{archivePath, files}
22+
cli := pzip.CLI{archivePath, files, runtime.GOMAXPROCS(0)}
2223
cli.Archive()
2324

2425
archiveReader := testutils.GetArchiveReader(t, archivePath)
@@ -32,7 +33,7 @@ func BenchmarkCLI(b *testing.B) {
3233
dirPath := filepath.Join(benchmarkRoot, "minibench")
3334
archivePath := filepath.Join(benchmarkRoot, "minibench.zip")
3435

35-
cli := pzip.CLI{archivePath, []string{dirPath}}
36+
cli := pzip.CLI{archivePath, []string{dirPath}, runtime.GOMAXPROCS(0)}
3637

3738
b.ReportAllocs()
3839
b.ResetTimer()

cmd/cli/main.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"log"
77
"os"
8+
"runtime"
89

910
"github.com/pzip"
1011
)
@@ -18,6 +19,9 @@ func main() {
1819
flag.PrintDefaults()
1920
}
2021

22+
var concurrency int
23+
flag.IntVar(&concurrency, "concurrency", runtime.GOMAXPROCS(0), "allow up to n compression routines")
24+
2125
flag.Parse()
2226

2327
args := flag.Args()
@@ -30,9 +34,7 @@ func main() {
3034
return
3135
}
3236

33-
archivePath := os.Args[1]
34-
35-
cli := pzip.CLI{ArchivePath: archivePath, Files: os.Args[2:]}
37+
cli := pzip.CLI{ArchivePath: args[0], Files: args[1:], Concurrency: concurrency}
3638
err := cli.Archive()
3739

3840
if err != nil {

0 commit comments

Comments
 (0)