storage

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: ISC Imports: 14 Imported by: 0

README

Storage

Pipeline status Coverage report

License

Compress and encrypt your directories 🗜️🔐

Principle

2 steps operation to produce an encrypted archive .enc1 from a directory:

  1. archive the origin directory with tar + gzip
  2. encrypt the archive with gpg

Usage

Initialization

import "gitlab.com/ggpack/storage-go"

// Using a byte slice
var password []byte
store := storage.NewStorage(password)

// Using a string
var password string
store := storage.NewStorageStr(password)

Make an archive from a directory

err := store.Archive("originDir", "destinationArchive.enc1")
if err != nil {
    log.Error("Archiving error", err)
}

Extract an archive to a directory

err := store.Retrieve("originArchive.enc1", "destinationDir")
if err != nil {
    log.Error("Retrieve error: ", err)
}

Contributing

Install

The code is hosted on Gitlab 🦊

Simply clone and submit merge requests.

Testing

The unit tests are located in the test folder code and ran by go.testing.

# Run all
go test ./test

Releasing

The process is triggered by a tag added to a commit. The tag must match the pattern v<VERSION> and VERSION has to comply to semver.

The package publication is automatically managed by go after the tagging, you can check it on pkg.go.dev after a few hours.

Thanks

Smashicons from www.flaticon.com for the icon.

Documentation

Overview

Directory compression/extraction functions Adapted from "github.com/walle/targz" (MIT)

Index

Constants

View Source
const (
	ErrRetrieveSourceNotFound = 0
	ErrDecryptPassword        = 1
	ErrDecryptGpg             = 2
	ErrExtractCreateDest      = 3
	ErrExtractUnzip           = 4
)

Variables

This section is empty.

Functions

func Compress

func Compress(inputDirPath string, includeRootFolder bool) (io.Reader, error)

Compress creates a archive from the folder inputDirPath and returns an io.Reader so that the caller can redirect it where he wants (file, socket, ...). It only adds the last directory in inputDirPath to the archive, not the whole path.

func Decrypt

func Decrypt(ciphertextReader io.Reader, password []byte) (io.Reader, error)

Reads the input `cypherTextReader` and decrypts it with `password` based on `openpgp` algo, then returns the result as an io.Reader. Up to the caller to redirect the output wherever he wants (file, Extract zip, ...).

func Encrypt

func Encrypt(plaintextReader io.Reader, password []byte) (io.Reader, error)

Reads the input `plaintextReader` and encrypts it with `password` based on `openpgp` algo, then returns the result as an io.Reader. Up to the caller to redirect the output wherever he wants (file, socket, ...).

func Extract

func Extract(zippedData io.Reader, outputDirPath string) error

Extract reads `zippedData` from the input io.Reader and stores it into the directory `outputDirPath`, recreating the tree structure.

Types

type Params added in v1.1.0

type Params map[string]any

Flexible way to pass params to the constructor

func (Params) Get added in v1.1.0

func (this Params) Get(key string, defaultVal any) any

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

Object owner of the encryption and compression options. Can be global (application wise) or contextual (session/user wise).

func NewStorage

func NewStorage(args Params) *Storage

func (*Storage) Archive

func (this *Storage) Archive(inputDirPath string, outputArchivePath string) error

Entrypoint to compress and encrypt a directory. Equivalent to the shell command: `tar cz -C $inputDirPath . | gpg -c --batch --yes --passphrase $aKey -o $outputArchivePath`

func (*Storage) Retrieve

func (this *Storage) Retrieve(inputArchivePath string, outputDirPath string) error

Entrypoint to decrypt and extract a directory. Equivalent to the shell command: `gpg -d --batch --yes --passphrase $aKey $inputArchivePath | tar -C $outputDirPath -xzf -`

type StorageError added in v0.1.0

type StorageError struct {
	// contains filtered or unexported fields
}

func NewStorageError added in v0.2.0

func NewStorageError(code int) *StorageError

func (*StorageError) Error added in v0.1.0

func (this *StorageError) Error() string

Jump to

Keyboard shortcuts

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