archivex

package module
v0.0.0-...-165acc5 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

README

archivex

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

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 Archivex

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

interface

type TarFile

type TarFile struct {
	Writer *tar.Writer
	Name   string
}

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 add all files from dir in archive

func (*TarFile) AddFile

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

AddFile add file from dir 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

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 add all files from dir in archive

func (*ZipFile) AddFile

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

AddFile add file from dir in archive

func (*ZipFile) AddFileAs

func (z *ZipFile) AddFileAs(name string, as 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

Jump to

Keyboard shortcuts

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