-
Notifications
You must be signed in to change notification settings - Fork 3
/
simple_extract.go
50 lines (42 loc) · 1.03 KB
/
simple_extract.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package boar
import (
"github.com/itchio/headway/state"
"github.com/itchio/httpkit/eos"
"github.com/itchio/httpkit/eos/option"
"github.com/itchio/savior"
"github.com/pkg/errors"
)
type SimpleExtractParams struct {
ArchivePath string
DestinationFolder string
Consumer *state.Consumer
}
func SimpleExtract(params *SimpleExtractParams) (*savior.ExtractorResult, error) {
f, err := eos.Open(params.ArchivePath, option.WithConsumer(params.Consumer))
if err != nil {
return nil, errors.WithStack(err)
}
defer f.Close()
ai, err := Probe(ProbeParams{
Consumer: params.Consumer,
File: f,
})
if err != nil {
return nil, errors.WithStack(err)
}
ex, err := ai.GetExtractor(f, params.Consumer)
if err != nil {
return nil, errors.WithStack(err)
}
ex.SetConsumer(params.Consumer)
sink := &savior.FolderSink{
Directory: params.DestinationFolder,
Consumer: params.Consumer,
}
defer sink.Close()
res, err := ex.Resume(nil, sink)
if err != nil {
return nil, errors.WithStack(err)
}
return res, nil
}