-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
567bf75
commit b0f6a6c
Showing
10 changed files
with
461 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
github: [Unpackerr] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: test-and-lint | ||
on: push | ||
permissions: | ||
contents: read | ||
jobs: | ||
gotest: | ||
strategy: | ||
matrix: | ||
os: [ubuntu, macos, windows] | ||
runs-on: ${{ matrix.os }}-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: 'stable' | ||
- name: go-generate | ||
run: go generate ./... | ||
- name: go-test | ||
run: go test ./pkg/... | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: 'v1.55' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
linters: | ||
enable-all: true | ||
disable: | ||
# deprecated | ||
- maligned | ||
- scopelint | ||
- interfacer | ||
- golint | ||
- exhaustivestruct | ||
- nosnakecase | ||
- structcheck | ||
- deadcode | ||
- varcheck | ||
- ifshort | ||
# unused | ||
- nlreturn | ||
- exhaustruct | ||
- depguard | ||
run: | ||
timeout: 3m | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# xt | ||
|
||
Extract Everything. Decompress entire folders filled with archives. | ||
|
||
Simple command-line tool that works on mac, windows and linux. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module github.com/Unpackerr/xt | ||
|
||
go 1.21 | ||
|
||
require golift.io/xtractr v0.2.3-0.20240118083145-be8544c18974 | ||
|
||
require ( | ||
github.com/andybalholm/brotli v1.0.6 // indirect | ||
github.com/bodgit/plumbing v1.3.0 // indirect | ||
github.com/bodgit/sevenzip v1.4.5 // indirect | ||
github.com/bodgit/windows v1.0.1 // indirect | ||
github.com/hashicorp/errwrap v1.1.0 // indirect | ||
github.com/hashicorp/go-multierror v1.1.1 // indirect | ||
github.com/kdomanski/iso9660 v0.4.0 // indirect | ||
github.com/klauspost/compress v1.17.4 // indirect | ||
github.com/nwaples/rardecode v1.1.3 // indirect | ||
github.com/pierrec/lz4/v4 v4.1.19 // indirect | ||
github.com/ulikunitz/xz v0.5.11 // indirect | ||
go4.org v0.0.0-20230225012048-214862532bf5 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"os" | ||
|
||
"github.com/Unpackerr/xt/pkg/xt" | ||
) | ||
|
||
func main() { | ||
log.SetFlags(0) | ||
|
||
jobs := parseJobs() | ||
if len(jobs) < 1 || len(jobs[0].Paths) < 1 { | ||
log.Printf("If you pass a directory, this app will extract every archive in it.") | ||
log.Fatalf("Usage: %s [-output <path>] <path> [paths...]", os.Args[0]) | ||
} | ||
|
||
for i, job := range jobs { | ||
log.Printf("Starting Job %d with %d paths, output: %s", i+1, len(job.Paths), job.Output) | ||
xt.Extract(job) | ||
} | ||
} | ||
|
||
func parseJobs() []*xt.Job { | ||
pwd, err := os.Getwd() | ||
if err != nil { | ||
pwd = "." | ||
} | ||
|
||
output := flag.String("output", pwd, "Output directory, default is current directory") | ||
|
||
flag.Parse() | ||
|
||
return []*xt.Job{{Output: *output, Paths: flag.Args()}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package xt | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"golift.io/xtractr" | ||
) | ||
|
||
type Job struct { | ||
Paths []string | ||
Output string | ||
} | ||
|
||
func Extract(job *Job) { | ||
archives := getArchives(job.Paths) | ||
if len(archives) == 0 { | ||
log.Println("==> No archives found in:", job.Paths) | ||
} | ||
|
||
total := 0 | ||
count := 0 | ||
|
||
for _, files := range archives { | ||
total += len(files) | ||
} | ||
|
||
for _, files := range archives { | ||
for _, fileName := range files { | ||
count++ | ||
log.Printf("==> Extracting Archive (%d/%d): %s", count, total, fileName) | ||
|
||
start := time.Now() | ||
|
||
size, files, _, err := xtractr.ExtractFile(&xtractr.XFile{ | ||
FilePath: fileName, // Path to archive being extracted. | ||
OutputDir: job.Output, // Folder to extract archive into. | ||
FileMode: 0o644, //nolint:gomnd // Write files with this mode. | ||
DirMode: 0o755, //nolint:gomnd // Write folders with this mode. | ||
Password: "", // (RAR) Archive password. Blank for none. | ||
}) | ||
if err != nil { | ||
log.Printf("[ERROR] Archive: %s: %v", fileName, err) | ||
continue | ||
} | ||
|
||
elapsed := time.Since(start).Round(time.Millisecond) | ||
log.Printf("==> Extracted Archive %s in %v: bytes: %d, files: %d", fileName, elapsed, size, len(files)) | ||
log.Printf("==> Files:\n - %s", strings.Join(files, "\n - ")) | ||
} | ||
} | ||
} | ||
|
||
func getArchives(paths []string) map[string][]string { | ||
archives := map[string][]string{} | ||
|
||
for _, fileName := range paths { | ||
fileInfo, err := os.Stat(fileName) | ||
if err != nil { | ||
log.Println("[ERROR] Reading archive path:", err) | ||
continue | ||
} | ||
|
||
if !fileInfo.IsDir() { | ||
archives[fileName] = []string{fileName} | ||
continue | ||
} | ||
|
||
for k, v := range xtractr.FindCompressedFiles(xtractr.Filter{Path: fileName}) { | ||
archives[k] = v | ||
} | ||
} | ||
|
||
return archives | ||
} |