archiver

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2022 License: MIT Imports: 15 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"
// ...

// This code packages, compresses and encrypts a directory ("user/projects").

// 1. Directory Packaging into a tar []byte (packedData) using PackFolder()
packedData, err := PackFolder("user/projects")
if err != nil{
    // ...
}

// 2. Compression process using Compress(). gzipData is a compressed []byte.
// The second param is the file name to store in the header name of the gzip file
gzipData, err := Compress(packedData, "projects.gz")
if err != nil{
    //...
}

// 3. Encryption process using Encrypt(). encryptedData is an encrypted []byte
encryptedData, err := Encrypt(gzipData, "mypassword")
if err != nil{
    //...
}

// 4. Write the result into a file named "backups/projects.crp" using WriteFile
err = WriteFile("backups/projects.crp", encryptedData)
if err != nil{
    //...
}

Api docs available here: https://pkg.go.dev/github.com/jjcapellan/jj-archiver

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 []byte, fileName string) ([]byte, error)

Compress compress bytes array of file into another bytes array.

fileName could include relative file path. It is stored in the header of the compressed file.

This param is important to preserve the original name of the file when uncompressed.

Example: Compress(filedata, "folder/uncompressedfile.ext")

func Decompress

func Decompress(input []byte) (output []byte, fileName string, e error)

Decompress decompress bytes array of file into another bytes array.

func Decrypt

func Decrypt(input []byte, password string) (output []byte, e error)

Decrypt decrypts input []byte] into output []byte using the password. This function uses AES256 algorithm (mode GCM).

func Encrypt

func Encrypt(input []byte, password string) (output []byte, e error)

Encrypt encrypts input []byte into output []byte 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.

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 PackArray added in v0.6.0

func PackArray(input []string) ([]byte, error)

PackArray packs folders and files of input string array into an array of bytes. This array can be used to write a tar file, or to process in another function.

Example: PackArray([]string{"myfolder/file.txt", "myfolder/folder2"}) returns []byte of the packed file

func PackFolder

func PackFolder(input string) ([]byte, error)

PackFolder packs input folder into an array of bytes. This array can be used to write a tar file, or to process in another function.

Example: PackFolder("user/projectsfolder") returns []byte of the packed file

func ReadFile added in v0.5.0

func ReadFile(fileName string) ([]byte, error)

func Unpack

func Unpack(input []byte, output string) error

Unpack extracts all files []byte of the input tar file to output path.

Example: Unpack(fileBytesArray, "unpackedfolders/folder1")

func WriteFile added in v0.5.0

func WriteFile(filePath string, data []byte, perm os.FileMode) error

WriteFile writes a []byte into a file

filePath: complete path of the file (example: folder1/file.ext). It will create a directory if necessary.

data: content to write

perm: file permissions. Example: 666, 746, ...

Types

This section is empty.

Jump to

Keyboard shortcuts

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