splitzip

package module
v0.0.0-...-2b532e4 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2018 License: MIT Imports: 9 Imported by: 0

README

splitzip

Allows you to define a maximum file size, and will split zip file output based on that size. Each zip file produced is a completely functional archive, i.e. it doesn't generate a single huge zip file then split that into pieces.

Example

Given a folder with a set of files of various sizes

sources/10mb-32.txt	10000000
sources/11mb-32.txt	11000000
sources/1mb-32.txt	1000000
sources/2mb-32.txt	2000000
sources/3mb-32.txt	3000000
sources/4mb-32.txt	4000000
sources/5mb-32.txt	5000000
sources/6mb-32.txt	6000000
sources/7mb-32.txt	7000000
sources/8mb-32.txt	8000000
sources/9mb-32.txt	9000000

the following program will archive all the text files above

package main

import (
	"fmt"
	"github.com/jar-o/splitzip"
)

func main() {
	fmt.Printf("Zip(), any error? %+v\n", splitzip.Zip("sources", "sources/zip", "test", 10000000, .4))
}

and will produce a numbered sequence of zip files smaller than the defined "max size" of 10MB:

sources/zip/test0.zip	9444579
sources/zip/test1.zip	9444588
sources/zip/test2.zip	9444622
sources/zip/test3.zip	9444513
sources/zip/test4.zip	3778674

The final parameter .4 in the call to splitzip.Zip() above is the expected average space savings for this set of files. Because the density of files will vary, and hence their compressibility, you can use this number to optimize for your set of file types. If you're not certain, just leave it as 0.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Zip

func Zip(inpath string, outpath string, prefix string, maxSize int64, savings float64) error

Types

type ByLargest

type ByLargest []FileSize

Interface to sort files largest -> smallest

func (ByLargest) Len

func (f ByLargest) Len() int

func (ByLargest) Less

func (f ByLargest) Less(i, j int) bool

func (ByLargest) Swap

func (f ByLargest) Swap(i, j int)

type FileSize

type FileSize struct {
	Size int64
	Path string
}

Jump to

Keyboard shortcuts

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