archivex

package module
v0.0.0-...-d91d420 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2017 License: BSD-3-Clause Imports: 10 Imported by: 0

README

archivex

archivex is a golang package that archives folders (recursively) and files to zip and tar formats.

Build Status

Installation

$ go get github.com/jhoonb/archivex

Example


package main

import (
	"github.com/jhoonb/archivex"
)

// Example using only func zip
func zip() {
	zip := new(archivex.ZipFile)
	zip.Create("filezip")
	zip.Add("testadd.txt", []byte("test 1"))
	zip.AddFile("<input_path_file_here>")
	zip.AddAll("<input_dir_here", true)
	zip.Close()
}

// Example using only func tar
func tar() {
	tar := new(archivex.TarFile)
	tar.Create("filetar")
	tar.Add("testadd.txt", []byte("test 1"))
	tar.AddFile("<input_path_file_here>")
	tar.AddAll("<input_dir_here", true)
	tar.Close()
}

// Example using interface
func usingInterface() {

	archx := []archivex.Archivex{&archivex.TarFile{}, &archivex.ZipFile{}}

	for _, arch := range archx {
		arch.Create("fileinterface")
		arch.Add("testadd.txt", []byte("file 1 :) "))
		arch.AddFile("<input_path_file_here>")
		arch.AddAll("<input_dir_here", true)
		arch.Close()
	}
}

func main() {

	zip()
	tar()
	usingInterface()
}

:)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArchiveWriteFunc

type ArchiveWriteFunc func(info os.FileInfo, file io.Reader, entryName string) (err error)

ArchiveWriteFunc is the closure used by an archive's AddAll method to actually put a file into an archive Note that for directory entries, this func will be called with a nil 'file' param

type Archivex

type Archivex interface {
	Create(name string) error
	CreateWithName(name string) error
	Add(name string, file []byte) error
	AddFile(name string) error
	AddAll(dir string, includeCurrentFolder bool) error
	Close() error
}

interface

type TarFile

type TarFile struct {
	Writer     *tar.Writer
	Name       string
	GzWriter   *gzip.Writer
	Compressed bool
}

TarFile implement *tar.Writer

func (*TarFile) Add

func (t *TarFile) Add(name string, file []byte) error

Add add byte in archive tar

func (*TarFile) AddAll

func (t *TarFile) AddAll(dir string, includeCurrentFolder bool) error

AddAll adds all files from dir in archive Tar does not support directories

func (*TarFile) AddFile

func (t *TarFile) AddFile(name string) error

AddFile add file from dir in archive tar

func (*TarFile) AddFileWithName

func (t *TarFile) AddFileWithName(name string, filename string) error

AddFile add file from dir in archive tar

func (*TarFile) AddWithHeader

func (t *TarFile) AddWithHeader(name string, file []byte, hdr *tar.Header) error

Add add byte in archive tar

func (*TarFile) Close

func (t *TarFile) Close() error

Close the file Tar

func (*TarFile) Create

func (t *TarFile) Create(name string) error

Create new Tar file

func (*TarFile) CreateWithName

func (t *TarFile) CreateWithName(name string) error

Create new Tar file with replace zip name

type ZipFile

type ZipFile struct {
	Writer *zip.Writer
	Name   string
}

ZipFile implement *zip.Writer

func (*ZipFile) Add

func (z *ZipFile) Add(name string, file []byte) error

Add add byte in archive zip

func (*ZipFile) AddAll

func (z *ZipFile) AddAll(dir string, includeCurrentFolder bool) error

AddAll adds all files from dir in archive, recursively. Directories receive a zero-size entry in the archive, with a trailing slash in the header name, and no compression

func (*ZipFile) AddFile

func (z *ZipFile) AddFile(name string) error

AddFile add file from dir in archive

func (*ZipFile) Close

func (z *ZipFile) Close() error

func (*ZipFile) Create

func (z *ZipFile) Create(name string) error

Create new file zip

func (*ZipFile) CreateWithName

func (z *ZipFile) CreateWithName(name string) error

Create new file zip with replace zip name

Jump to

Keyboard shortcuts

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