Skip to content

Commit

Permalink
Merge pull request #58 from bodgit/volumes
Browse files Browse the repository at this point in the history
Add Volumes method
  • Loading branch information
bodgit authored Dec 18, 2022
2 parents 62668b6 + 1908834 commit 2b624be
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ require (
github.com/hashicorp/go-multierror v1.1.1
github.com/klauspost/compress v1.15.13
github.com/pierrec/lz4/v4 v4.1.17
github.com/stretchr/testify v1.8.1
github.com/ulikunitz/xz v0.5.11
go4.org v0.0.0-20200411211856-f5505b9728dd
golang.org/x/text v0.5.0
)

require github.com/hashicorp/errwrap v1.0.0 // indirect
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.15.13 h1:NFn1Wr8cfnenSJSA46lLq4wHCcBzKTSjnBIexDMMOV0=
github.com/klauspost/compress v1.15.13/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pierrec/lz4/v4 v4.1.17 h1:kV4Ip+/hUBC+8T6+2EgburRtkE9ef4nbY3f4dFhGjMc=
github.com/pierrec/lz4/v4 v4.1.17/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
Expand Down Expand Up @@ -253,6 +255,7 @@ google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
10 changes: 10 additions & 0 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,16 @@ func (z *Reader) init(r io.ReaderAt, size int64) error {
return nil
}

// Volumes returns the list of volumes that have been opened as part of the current archive.
func (rc *ReadCloser) Volumes() []string {
volumes := make([]string, len(rc.f))
for idx, f := range rc.f {
volumes[idx] = f.Name()
}

return volumes
}

// Close closes the 7-zip file or volumes, rendering them unusable for I/O.
func (rc *ReadCloser) Close() error {
var err *multierror.Error
Expand Down
22 changes: 22 additions & 0 deletions reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/bodgit/sevenzip"
"github.com/bodgit/sevenzip/internal/util"
"github.com/stretchr/testify/assert"
)

func readArchive(t *testing.T, r *sevenzip.ReadCloser) {
Expand Down Expand Up @@ -45,6 +46,7 @@ func TestOpenReader(t *testing.T) {

tables := []struct {
name, file string
volumes []string
}{
{
name: "no header compression",
Expand All @@ -57,6 +59,14 @@ func TestOpenReader(t *testing.T) {
{
name: "multiple volume",
file: "multi.7z.001",
volumes: []string{
"multi.7z.001",
"multi.7z.002",
"multi.7z.003",
"multi.7z.004",
"multi.7z.005",
"multi.7z.006",
},
},
{
name: "empty streams and files",
Expand Down Expand Up @@ -119,6 +129,18 @@ func TestOpenReader(t *testing.T) {
}
defer r.Close()

volumes := []string{}

if table.volumes != nil {
for _, v := range table.volumes {
volumes = append(volumes, filepath.Join("testdata", v))
}
} else {
volumes = append(volumes, filepath.Join("testdata", table.file))
}

assert.Equal(t, volumes, r.Volumes())

readArchive(t, r)
})
}
Expand Down

0 comments on commit 2b624be

Please sign in to comment.