createzip

package module
v0.0.0-...-6eba221 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2017 License: MIT Imports: 7 Imported by: 0

README

createzip

Build Status Go Report Card GoDoc

createzip is a Golang package which creates local zip files or downloadable zip files for HTTP server.

Example to Create the Zip for HTTP Server

You may find the example in ./example/main.go

func hello(w http.ResponseWriter, r *http.Request) {
    // Create zip file for HTTP server
    zf := createzip.NewForHTTP(w, "new.zip")
    // Add file into zip file. 1st param is the real file path, 2nd param is the file name in the zip file.
    // If file name in the zip file is empty, it will put the file in the root dir of the zip.
    zf.AddFile("./README.md", "")
    zf.AddFile("./main.go", "example/main.go")
    zf.Close()
}
Run Example

./example

Documentation
License

Documentation

Overview

Package createzip is a helper to create a new zip file and add files into the zip file.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DEBUG is debug mode.
	// Set to true to enable debug messages from this package.
	DEBUG = false
)

Functions

This section is empty.

Types

type ZipFile

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

ZipFile is wrapper of zip.Writer.

func New

func New(w io.Writer) (zf *ZipFile)

New creates a new zip file. It should call Close() after use.

func NewForHTTP

func NewForHTTP(w http.ResponseWriter, zipFileName string) (zf *ZipFile)

NewForHTTP creates the downloadable zip for HTTP server dynamically.

func (*ZipFile) Add

func (zf *ZipFile) Add(fileNameInZip string, r io.Reader) (err error)

Add creates a new file in the zip and copy the content from io.Reader.

Params:
    fileNameInZip: file name(path) in the zip.
    r: io.Reader. It will copy the io.Reader to the new create file's writer.

func (*ZipFile) AddFile

func (zf *ZipFile) AddFile(srcFilePath, fileNameInZip string) (err error)

AddFile creates a new file in the zip and copy the content from the original source file.

Params:
    srcFilePath: original file path.
    fileNameInZip: file name(path) in the zip. If it's empty(""), the file name will be root dir of the zip("./") + file name without dir of original source file.

func (*ZipFile) Close

func (zf *ZipFile) Close()

Close closes the writer of zip. It should call Close() after use.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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