...
 
Commits (2)
......@@ -3,11 +3,19 @@
package boar
import (
"fmt"
"io"
"github.com/itchio/boar/memfs"
"github.com/itchio/savior"
"github.com/itchio/wharf/state"
)
var _dummyConsumer = &state.Consumer{}
var _dummyConsumer = &state.Consumer{
OnMessage: func(lvl string, message string) {
fmt.Printf("[%s] %s", lvl, message)
},
}
func Fuzz(data []byte) int {
file := memfs.New(data, "data")
......@@ -16,8 +24,25 @@ func Fuzz(data []byte) int {
Consumer: _dummyConsumer,
}
if _, err := Probe(params); err != nil {
info, err := Probe(params)
if err != nil {
return 0
}
_, err = file.Seek(0, io.SeekStart)
if err != nil {
return 0
}
ex, err := info.GetExtractor(file, _dummyConsumer)
if err != nil {
return 0
}
_, err = ex.Resume(nil, &savior.NopSink{})
if err != nil {
return 0
}
return 1
}
......@@ -2,10 +2,14 @@ package boar
import (
"errors"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
"time"
"github.com/itchio/wharf/eos"
"github.com/itchio/wharf/state"
"github.com/stretchr/testify/assert"
)
......@@ -94,3 +98,48 @@ func (ffi fakeFileInfo) Mode() os.FileMode {
func (ffi fakeFileInfo) Sys() interface{} {
return nil
}
func Test_RealFiles(t *testing.T) {
files, err := ioutil.ReadDir("testdata")
if err != nil {
panic(err)
}
consumer := &state.Consumer{}
for _, f := range files {
t.Run(f.Name(), func(t *testing.T) {
file, err := eos.Open(filepath.Join("testdata", f.Name()))
if err != nil {
panic(err)
}
defer file.Close()
ai, err := Probe(&ProbeParams{
File: file,
Consumer: consumer,
})
if err != nil {
panic(err)
}
tokens := strings.Split(f.Name(), "-")
lastToken := tokens[len(tokens)-1]
expectedType := lastToken
switch lastToken {
case "dmg":
expectedType = "hfs"
case "rar4":
expectedType = "rar"
case "gz":
expectedType = "tar.gz"
case "bz2":
expectedType = "tar.bz2"
case "xz":
expectedType = "tar.xz"
}
assert.EqualValues(t, expectedType, ai.Format)
})
}
}
......@@ -130,7 +130,7 @@ func New(file eos.File, consumer *state.Consumer) (SzExtractor, error) {
return nil, errors.Errorf("could not open with 7-zip, tried %v", attempts)
}
se.format = se.archive.GetArchiveFormat()
se.format = strings.ToLower(se.archive.GetArchiveFormat())
if se.format == "7z" {
// .7z is a known non-resumable format - resuming means a lot
// of extra IO and decompression work on already-extracted blocks,
......
......@@ -28,7 +28,9 @@ func New(file eos.File, consumer *state.Consumer) (*xzSource, error) {
subConsumer := &state.Consumer{
OnMessage: func(level string, message string) {
consumer.OnMessage(level, message)
if consumer.OnMessage != nil {
consumer.OnMessage(level, message)
}
},
OnProgress: func(progress float64) {
xs.progress = progress
......
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added