archive

package
v0.0.0-...-475c3b8 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

README

archive

Archive combines Go's archive/zip & tar into a simpler, higher-level API

GoDoc

Features
  • Simple
  • Supports tar, tar.gz and zip
  • Great for streaming directories over the network (e.g. see serve(1))
Quick Usage
package main

import (
	"os"

	"github.com/jpillora/archive"
)

func main() {
	a := archive.NewTarGzWriter(os.Stdout)
	a.AddBytes("foo.txt", []byte("hello foo!"))
	a.AddBytes("dir/bar.txt", []byte("hello bar!"))
	a.Close()
}
$ go run example.go | tar zxvf -
x foo.txt
x dir/bar.txt

See the example/ for more

Todo
  • Add extraction support
  • Add .7z archive type
  • Add .lz compression type
MIT License

Copyright © 2015 Jaime Pillora <dev@jpillora.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TarFileMode = os.FileMode(0755)

Functions

func Extension

func Extension(path string) string

Get archiver extension from path

func ValidExtension

func ValidExtension(path string) bool

Has a valid archiver extension

Types

type Archive

type Archive struct {
	//config
	DirMaxSize  int64 //defaults to no limit (-1)
	DirMaxFiles int   //defaults to no limit (-1)
	// contains filtered or unexported fields
}

Archive** combines Go's archive/zip,tar into a simpler, higher-level API

func NewTarGzWriter

func NewTarGzWriter(dst io.Writer) *Archive

func NewTarWriter

func NewTarWriter(dst io.Writer) *Archive

func NewWriter

func NewWriter(filename string, dst io.Writer) (*Archive, error)

NewWriter is useful when you'd like a dynamic archive type using a filename with extension

func NewZipWriter

func NewZipWriter(dst io.Writer) *Archive

func (*Archive) AddBytes

func (a *Archive) AddBytes(path string, contents []byte) error

func (*Archive) AddDir

func (a *Archive) AddDir(path string) error

func (*Archive) AddFile

func (a *Archive) AddFile(path string, f *os.File) error

func (*Archive) AddInfoFile

func (a *Archive) AddInfoFile(path string, info os.FileInfo, f *os.File) error

You can prevent archive from performing an extra Stat by using AddInfoFile instead of AddFile

func (*Archive) Close

func (a *Archive) Close() error

Directories

Path Synopsis
example
dir

Jump to

Keyboard shortcuts

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