Skip to content

Commit

Permalink
feat: add extract support.
Browse files Browse the repository at this point in the history
  • Loading branch information
syhily committed Nov 15, 2022
1 parent 2bd7ade commit 0bd3686
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
github.com/schollz/progressbar/v3 v3.12.1
github.com/spf13/cobra v1.6.1
github.com/yi-ge/unzip v1.0.2
go.uber.org/ratelimit v0.2.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/yi-ge/unzip v1.0.2 h1:Mz1+LxvTNV78eWDSyYOitiB+wNS7aSGzDj8KG0SeTaA=
github.com/yi-ge/unzip v1.0.2/go.mod h1:CdcCDDd6KIIr9DK3TaaliK0hJzzTlw9WypEcTcdlYKI=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/ratelimit v0.2.0 h1:UQE2Bgi7p2B85uP5dC2bbRtig0C+OeNRnNEafLjsLPA=
Expand Down
8 changes: 8 additions & 0 deletions internal/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"strconv"
"sync"

"github.com/yi-ge/unzip"

"github.com/bookstairs/bookhunter/internal/log"
"github.com/bookstairs/bookhunter/internal/naming"
"github.com/bookstairs/bookhunter/internal/progress"
Expand Down Expand Up @@ -153,6 +155,12 @@ func (f *commonFetcher) downloadFile(bookID int64, format Format) error {
return err
}

// Extract the archives.
if format.Archive() && f.Extract {
u := unzip.New(path, f.DownloadPath)
return u.Extract()
}

return nil
}

Expand Down

0 comments on commit 0bd3686

Please sign in to comment.