Skip to content

Commit

Permalink
Add xt
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall committed Jan 19, 2024
1 parent 567bf75 commit b0f6a6c
Show file tree
Hide file tree
Showing 10 changed files with 461 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [Unpackerr]
File renamed without changes.
23 changes: 23 additions & 0 deletions .github/workflows/codetests.yml
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'
21 changes: 21 additions & 0 deletions .golangci.yml
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

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Unpackerr
Copyright (c) 2023-2024 David Newhall II

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 3 additions & 0 deletions README.md
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.
21 changes: 21 additions & 0 deletions go.mod
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
)
277 changes: 277 additions & 0 deletions go.sum

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

Check failure on line 1 in main.go

View workflow job for this annotation

GitHub Actions / gotest (windows)

File is not `gci`-ed with --skip-generated -s standard -s default (gci)

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()}}
}
77 changes: 77 additions & 0 deletions pkg/xt/xt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package xt

Check failure on line 1 in pkg/xt/xt.go

View workflow job for this annotation

GitHub Actions / gotest (windows)

File is not `gci`-ed with --skip-generated -s standard -s default (gci)

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
}

0 comments on commit b0f6a6c

Please sign in to comment.