does it support multi-volumes decompression?
wotmshuaisi opened this issue · 3 comments
wotmshuaisi commented
can this project deal with files like this?
a.7z.001
a.7z.002
a.7z.003
a.7z.004
bodgit commented
Not directly, no.
However the library just wants something that implements the io.ReaderAt
interface and as the archive is just the concatenation of its parts, all you need is something similar to io.MultiReader()
to join the parts/volumes together but with the right interface. Thankfully such a thing already exists in readerutil.NewMultiReaderAt(). The following code works:
package main
import (
"errors"
"io"
"log"
"os"
"github.com/bodgit/sevenzip"
"go4.org/readerutil"
)
func main() {
sr := make([]readerutil.SizeReaderAt, 0, len(os.Args[1:]))
for _, part := range os.Args[1:] {
f, err := os.Open(part)
if err != nil {
log.Fatal(err)
}
defer f.Close()
size, ok := readerutil.Size(f)
if !ok {
log.Fatal(errors.New("unable to calculate size"))
}
sr = append(sr, io.NewSectionReader(f, 0, size))
}
mr := readerutil.NewMultiReaderAt(sr...)
r, err := sevenzip.NewReader(mr, mr.Size())
if err != nil {
log.Fatal(err)
}
// Do something with r
}
I'm undecided whether to add this functionality to the library but the above code will work regardless.
bodgit commented
I've merged support for dealing with multiple volumes, just open the file of the first volume, i.e.:
r, err := sevenzip.OpenReader("archive.7z.001")
if err != nil {
log.Fatal(err)
}
defer r.Close()
wotmshuaisi commented
thanks a lot