archiver

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2022 License: MIT Imports: 16 Imported by: 1

README

GitHub tag (latest by date) GitHub license

JJ-ARCHIVER

A simple convenience utility library to pack (tar), compress (gzip) and encrypt (AES256 GCM) files.

Usage

// ...
import . "github.com/jjcapellan/jj-archiver"
// ...

// Pack folder "user/projects" into file "./projects.tar"
err := PackFolder("user/projects", "projects")
if err!= nil {
 //   ...
}

// Compress file "projects.tar" into "user/compressed/projects.tar.gz"
err := Compress("projects.tar", "user/compressed")
if err!= nil {
 //   ...
}

// Encrypt file "user/compressed/projects.tar.gz" into "./projects.tar.gz.crp"
err := Encrypt("user/compressed/projects.tar.gz", "", "mypassword")
if err!= nil {
 //   ...
}

// Decrypt file "./projects.tar.gz.crp" into "./projects.tar.gz"
err := Decrypt("projects.tar.gz.crp","", "mypassword")
if err!= nil {
 //   ...
}

// Decompress file "./projects.tar.gz" into "./projects.tar"
err := Decompress("projects.tar.gz", "")
if err!= nil {
 //   ...
}

// Unpack file "./projects.tar" in folder "user/copyfolder"
err := Unpack("projects.tar", "user/copyfolder")
if err!= nil {
 //   ...
}

// Get uncompressed file size (bytes)
size, err := GetDecompressedSize("projects.tar.gz")
if err != nil {
    // ...
}

// Verify compressed file using crc32 checksum
fileCRC32, _ := GetCRC32("projects.tar")
gzipCRC32, _ := GetGzipCRC32("projects.tar.gz")
isValid := (fileCRC32 == gzipCRC32)


Dependencies

This library is built over standard golang libraries, so it hasn't external dependencies.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compress

func Compress(input string, output string) error

Compress compress input file into output path. ".gz" extension is added to output.

If output == "" then generated file is saved in current directory.

Example: Compress("folder1/myfile.tar", "") generates "./myfile.tar.gz"

func Decompress

func Decompress(input string, output string) error

Decompress decompress input file into output path.

If output == "" then uses current directory.

Example: Decompress("projects.gz", "user/projectsfolder")

func Decrypt

func Decrypt(input string, output string, password string) error

Decrypt decrypts input file into output path using the password. This function uses AES256 algorithm (mode GCM).

Input file must have the extension ".crp"

If output == "" then uses current directory.

Example: Decrypt("projects.tar.gz.crp", "") generates "./projects.tar.gz"

func Encrypt

func Encrypt(input string, output string, password string) error

Encrypt encrypts input file into output path using the password. This function uses AES256 algorithm (mode GCM).

Password lenght can be any not zero value. The password is processed by the SHA256 hash algorithm to generate a 256-bit key.

If output == "" then uses current directory.

Example: Encrypt("projects.tar.gz", "") generates "./projects.tar.gz.crp"

func GetCRC32 added in v0.4.0

func GetCRC32(fileName string) (uint32, error)

GetCRC32 gets the crc32 of any file using IEEE polynomial

func GetDecompressedSize added in v0.4.0

func GetDecompressedSize(fileName string) (uint32, error)

GetDecompressedSize gets decompresed size of the gzip file.

func GetGzipCRC32 added in v0.4.0

func GetGzipCRC32(fileName string) (uint32, error)

GetGzipCRC32 gets crc32 checksum of decompressed file stored in gzip file (fileName)

func PackFolder

func PackFolder(input string, output string) error

PackFolder packs input folder into output tar file. ".tar" extension is added to the output file name.

Example: PackFolder("user/projectsfolder", "projects") generates "./projects.tar"

func Unpack

func Unpack(input string, output string) error

Unpack extracts all files from input tar file to output path.

Example: Unpack("packedfiles/myfile.tar", "unpackedfolders/folder1")

Types

This section is empty.

Jump to

Keyboard shortcuts

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