packutil

package module
v0.0.0-...-81d505a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2025 License: MPL-2.0 Imports: 17 Imported by: 0

README

UnpackIt

GoDoc Build Status

This Go library allows you to easily unpack the following files using magic numbers:

  • tar.gz
  • tar.bzip2
  • tar.xz
  • zip
  • tar

Usage

Unpack a file:

    file, _ := os.Open(test.filepath)
    err := unpackit.Unpack(file, tempDir)

Unpack a stream (such as a http.Response):

    res, err := http.Get(url)
    err := unpackit.Unpack(res.Body, tempDir)

Documentation

Overview

Package unpackit allows you to easily unpack *.tar.gz, *.tar.bzip2, *.tar.xz, *.zip and *.tar files. There are not CGO involved nor hard dependencies of any type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MagicNumber

func MagicNumber(reader *bufio.Reader, offset int) (string, error)

Check whether a file has the magic number for tar, gzip, bzip2 or zip files

Note that this function does not advance the Reader.

50 4b 03 04 for pkzip format 1f 8b for .gz format 42 5a for .bzip format 75 73 74 61 72 at offset 257 for tar files fd 37 7a 58 5a 00 for .xz format

func Sanitize

func Sanitize(name string) string

Sanitizes name to avoid overwriting sensitive system files when unarchiving

func UnpackFS

func UnpackFS(fs fs.FS, filename string, destPath string) error

UnpackFS is a helper function to easily unpack files.

func UnpackFile

func UnpackFile(filename string, destPath string) error

UnpackFile is a helper function to easily unpack TAR files

func UnpackReader

func UnpackReader(reader io.Reader, destPath string) error

UnpackReader unpacks a compressed stream. Magic numbers are used to determine what decompressor and/or unarchiver to use.

func UntarFS

func UntarFS(fs fs.FS, filename string, destPath string) error

UntarFS is a helper function to easily unpack TAR files

func UntarFile

func UntarFile(filename string, destPath string) error

UntarFile is a helper function to easily unpack TAR files

func UntarReader

func UntarReader(data io.Reader, destPath string) error

UntarReader unarchives a TAR archive and returns the final destination path or an error

func UnzipFS

func UnzipFS(fs fs.FS, filename string, destPath string) error

UnzipFS is a helper function to easily unpack ZIP files

func UnzipFile

func UnzipFile(filename string, destPath string) error

UnzipFile is a helper function to easily unpack ZIP files

func UnzipReader

func UnzipReader(r io.Reader, destPath string) error

UnzipReader unpacks a ZIP stream. When given a os.File reader it will get its size without reading the entire zip file in memory.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL