packdir

package module
v0.0.2-0...-da54f68 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2018 License: LGPL-3.0 Imports: 11 Imported by: 0

README

packdir

Quickly zip a directory with relative paths (compatible with common Zip tools).

This is a Go library to zip a directory in standard format with relative paths. It doesn't offer any fancy options yet and has not been tested very extensively. Tests will be added later.

TODO

In the future this package will allow you to unzip a snapshot, maintain some meta information, and will be tested extensively in order to make it suitable for production use. For now, it kind of works but use it at your own risk.

Documentation

Overview

Pack a directory into a zip file with relative paths and one base directory. This can be used for quickly snapshoting a directory and should be compatible with standard zip tools.

Index

Constants

View Source
const (
	PRINT_INFO   = 1
	PRINT_ERRORS = 2
	PROGRESSBAR  = 4
	VERBOSE      = 8
)

Flags to control the display and logging of events at the console.

View Source
const (
	HUFFMAN_ONLY        = -2
	DEFAULT_COMPRESSION = -1
	NO_COMPRESSION      = 0
	LEVEL1              = 1
	LEVEL2              = 2
	LEVEL3              = 3
	LEVEL4              = 4
	LEVEL5              = 5
	LEVEL6              = 6
	LEVEL7              = 7
	LEVEL8              = 8
	LEVEL9              = 9
	FAIR_COMPRESSION    = 2
	GOOD_COMPRESSION    = 5
	BEST_COMPRESSION    = 9
)

The compression levels that are available.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompressionLevel

type CompressionLevel int

Compression level.

type PackResult

type PackResult struct {
	FileNum       int64
	ScanErrNum    int64
	ArchiveErrNum int64
}

PackResult holds results of a packing operation. ScanErrNum represents the number of errors during file scanning, whereas ArchiveErrNum is the number of errors during archiving.

func Pack

func Pack(source string, outfile string, targetBaseDir string,
	level CompressionLevel, flags int) (*PackResult, error)

Pack a directory, where symlinks are not followed. The source must be a directory path and outfile is a file path. The targetBaseDir is a directory prefix relative which the files are stored. If it is omitted, then it will be "snapshot", so all files will be in snapshot/file1, snapshot/file2, etc. The compression level needs to be one of the zip compression levels defined by constants, otherwise it is set to 2. The flags are used to set the log level, e.g. PRINT_ERRORS | PRINT_INFO will print errors and general info, but not a progress bar and won't list files.

The result of this function is a PackResult structure and an error. The error should be checked to see if the operation succeeded at all. The result structure contains information about individual file errors. It is possible for the error to be nil even though individual file errors occurred.

Jump to

Keyboard shortcuts

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