Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BestCompressionZipWriter ¶
BestCompressionZipWriter returns a zip.Writer that registers flate.BestCompression as its compressor.
func DefaultProgressReporter ¶
DefaultProgressReporter is the default report that only reports upon a file being successfully added to archive.
Types ¶
type ProgressReporter ¶
ProgressReporter is called to provide update on compressing individual files.
- src: path of the file being added to the archive
- dst: relative path of the file in the archive
- written: number of bytes of the file that has been read and written to archive so far
- done: is true only when the file has been read and written in its entirety
The method will be called at least once for every file being compressed. If the file is small enough to fit into one read (see DefaultBufferSize), then the method is called exactly once with `done` being true.
func NewDirectoryProgressReporter ¶
func NewDirectoryProgressReporter(ctx context.Context, root string, reporter func(src, dst string, written, size int64, done bool, wc, fc int)) (ProgressReporter, error)
NewDirectoryProgressReporter creates a progress reporter intended to be used for compressing a directory.
Specifically, the new progress reporter is aware of how many files are there to be compressed by doing a preflight filepath.WalkDir (also cancellable), and for each file being compressed, the reporter is aware of the total number of bytes for that file. If the initial filepath.WalkDir fails, its error wil be returned.
- src: path of the file being added to the archive
- dst: relative path of the file in the archive
- written: number of bytes of the file that has been read and written to archive so far
- size: the total number of bytes of the file being compressed. Can be -1 if os.Stat fails.
- done: is true only when the file has been read and written in its entirety (written==size)
- wc: the number of files that has been written to archive so far
- fc: the total number of files to be written to archive
func NewProgressBarReporter ¶
func NewProgressBarReporter(ctx context.Context, root string, bar *progressbar.ProgressBar) (ProgressReporter, error)
NewProgressBarReporter creates a progress report that uses the specified progressbar.ProgressBar.
If the given progress bar is nil, it will be created with progressbar.DefaultBytes.
type Zipper ¶
type Zipper struct { // ProgressReporter controls how progress is reported. ProgressReporter ProgressReporter // NewWriter allows customization of the zip.Writer being used. // // Default to BestCompressionZipWriter. NewWriter func(w io.Writer) *zip.Writer }
Zipper is used to recursively compress (with zip) a directory or file with progress report and cancellable context.
func New ¶
func New() *Zipper
New creates a new Zipper with default settings.
By default, log.Printf will be used to provide progress update only on each file being added to the archive.
func (Zipper) CompressDir ¶
CompressDir compresses a directory recursively to the archive opened as io.Writer.
JunkRoot determines whether all compressed files are under a single root directory hierarchy or not.
For example, when compressing directory named "test" (root="test") with JunkRoot being false, all files in that directory and their children will be added to archive using these paths:
test/a.txt test/path/b.txt test/another/path/c.txt
If JunkRoot is true, the files will use these paths:
a.txt path/b.txt another/path/c.txt