archive

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2019 License: MIT Imports: 17 Imported by: 1

README

archive

Compress Static Webserver Files

func main() {
    fileList, err := archive.CompressWebserverFiles("./build/")
    if err != nil {
        fmt.Printf("unable to compress static webserver files because: %v\n", err)
    }
    fmt.Printf("compressed the following: %v\n", fileList)
}

Serve Static Webserver Files

func main() {
    mux := http.NewServeMux()
    mux.Handle("/", archive.FileServer(http.Dir("./build/")))
    http.ListenAndServe(":80", mux)
}

Create Gzipped CSV and Insert Into Tarball

func main() {
    csvData := [][]string{}
    csvData = append(csvData, []string{
        "hello world", "I'm a csv line",
    })
    archiver := archive.NewArchiver()
    archiver.AddCSV("csvData", csvData)
    archiver.CreateArchive("output")
    archiver.Destroy()
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPathIsDirectory          = errors.New("path is a directory")
	ErrPathIsNotDirectory       = errors.New("path is not a directory")
	ErrArchiverHasBeenDestroyed = errors.New("archiver has been destroyed")
	ErrNothingToArchive         = errors.New("nothing to archive")
	ErrContentTypeNotFound      = errors.New("content type not found")
)

package level errors

Functions

func BrotliAndGzipFiles

func BrotliAndGzipFiles(dir string, rgx *regexp.Regexp) ([]string, error)

BrotliAndGzipFiles recursively compresses of all regex matched files in a given directory structure

func CompressWebserverFiles

func CompressWebserverFiles(dir string) ([]string, error)

CompressWebserverFiles recursively zips common webserver files in a given directory structure

func FileServer

func FileServer(root http.Dir) http.Handler

FileServer will search for and serve compressed files if they are available

Types

type Archiver

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

Archiver is used to create tar.gz archives

func NewArchiver

func NewArchiver() *Archiver

NewArchiver creates an archiver

func (*Archiver) AddCSV

func (a *Archiver) AddCSV(filename string, lines [][]string) error

AddCSV creates a temporary csv file to be archived when CreateArchive() is called

func (*Archiver) CreateArchive

func (a *Archiver) CreateArchive(p string) error

CreateArchive moves all pending temporary files into a tar.gz

func (*Archiver) Destroy

func (a *Archiver) Destroy()

Destroy closes destroyChan to signal the destruction of this Archiver

Jump to

Keyboard shortcuts

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