feat: initial goget release — modern IPv6-first download utility
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
//go:build linux || freebsd
|
||||
// +build linux freebsd
|
||||
|
||||
package archive
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type ExtractConfig struct {
|
||||
DestDir string
|
||||
StripComponents int
|
||||
IncludePatterns []string
|
||||
ExcludePatterns []string
|
||||
PreservePermissions bool
|
||||
Overwrite bool
|
||||
Verbose bool
|
||||
}
|
||||
|
||||
func DefaultExtractConfig() *ExtractConfig {
|
||||
return &ExtractConfig{
|
||||
DestDir: ".", StripComponents: 0, IncludePatterns: []string{},
|
||||
ExcludePatterns: []string{}, PreservePermissions: true, Overwrite: true, Verbose: false,
|
||||
}
|
||||
}
|
||||
|
||||
func ExtractFile(srcPath, destDir string, cfg *ExtractConfig) error {
|
||||
if cfg == nil {
|
||||
cfg = DefaultExtractConfig()
|
||||
}
|
||||
srcFile, err := os.Open(srcPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open source file: %w", err)
|
||||
}
|
||||
defer srcFile.Close()
|
||||
return AutoExtract(filepath.Base(srcPath), srcFile, destDir)
|
||||
}
|
||||
|
||||
func ShouldExtractFile(filename string) bool { return IsArchiveFormat(filename) }
|
||||
func ListSupportedFormats() []string { return ListSupported() }
|
||||
func SupportsFormat(format string) bool { return Supports(format) }
|
||||
Reference in New Issue
Block a user