zip7

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 7 Imported by: 1

README

PkgGoDev GitHub Actions CI Status GoReportCard Codebeat badge GitHub Actions CodeQL Status

InstallationCompatibility and OS supportBuild StatusContributingLicense


zip7 package provides methods for working with 7z archives (p7zip wrapper).

Installation

Make sure you have a working Go 1.15+ workspace (instructions), then:

go get pkg.re/essentialkaos/zip7.v1

If you want to update zip7 to latest stable release, do:

go get -u pkg.re/essentialkaos/zip7.v1

Compatibility and OS support

Version 1.x
p7zip 9.x Partial
p7zip 15.x Full
p7zip 16.x Full
OS Support
Linux
Mac OS X
FreeBSD
Windows

Build Status

Branch Status
master CI
develop CI

Contributing

Before contributing to this project please read our Contributing Guidelines.

License

Apache License, Version 2.0

Documentation

Overview

Package zip7 provides methods for working with 7z archives (p7zip wrapper)

Index

Examples

Constants

View Source
const (
	TYPE_7Z   = "7z"
	TYPE_ZIP  = "zip"
	TYPE_GZIP = "gzip"
	TYPE_XZ   = "xz"
	TYPE_BZIP = "bzip2"
)

List of supported formats

Variables

This section is empty.

Functions

func Add

func Add(props Props, files ...string) (string, error)

Add adds file or files to archive

Example
input := "log.txt"
output := "log.7z"

out, err := Add(
	Props{
		File:        output,
		Compression: 6,
		Password:    "mYSuppaPAssWORD",
		Threads:     4,
		Delete:      true,
	}, input)

fmt.Printf("p7zip output: %s\n", out)
fmt.Printf("Error: %v\n", err)
Output:

func AddList

func AddList(props Props, files []string) (string, error)

AddList adds files to archive from slice

Example
input1 := "log1.txt"
input2 := "log2.txt"
input3 := "log3.txt"
output := "log.7z"

out, err := AddList(Props{File: output}, []string{input1, input2, input3})

fmt.Printf("p7zip output: %s\n", out)
fmt.Printf("error: %v\n", err)
Output:

func Check

func Check(props Props) (bool, error)

Check tests archive

Example
ok, err := Check(Props{File: "log.7z"})

fmt.Printf("File ok: %t\n", ok)
fmt.Printf("Error: %v\n", err)
Output:

func Delete

func Delete(props Props, files ...string) (string, error)

Delete removes files from archive

Example
out, err := Delete(Props{File: "log.7z"}, "dir1/file1", "dir2/file2")

fmt.Printf("p7zip output: %s\n", out)
fmt.Printf("Error: %v\n", err)
Output:

func Extract

func Extract(props Props) (string, error)

Extract extracts arhive

Example
out, err := Extract(Props{File: "log.7z"})

fmt.Printf("p7zip output: %s\n", out)
fmt.Printf("Error: %v\n", err)
Output:

Types

type FileInfo

type FileInfo struct {
	Modified   time.Time
	Created    time.Time
	Accessed   time.Time
	Method     []string
	Path       string
	Folder     string
	Attributes string
	Comment    string
	HostOS     string
	Size       int
	PackedSize int
	CRC        int
	Block      int
	Version    int
	Encrypted  bool
}

FileInfo contains info about file inside archive

type Info

type Info struct {
	Method       []string
	Files        []*FileInfo
	Path         string
	Type         string
	Blocks       int
	PhysicalSize int
	HeadersSize  int
	Solid        bool
}

Info contains info about archive

func List

func List(props Props) (*Info, error)

List returns info about archive

Example
info, err := List(Props{File: "log.7z"})

if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}

fmt.Printf("Path: %s\n", info.Path)
fmt.Printf("Type: %s\n", info.Type)
fmt.Printf("Solid: %t\n", info.Solid)
fmt.Printf("Blocks: %d\n", info.Blocks)
fmt.Printf("PhysicalSize: %d\n", info.PhysicalSize)
fmt.Printf("HeadersSize: %d\n", info.HeadersSize)

fmt.Println("Files:")

for _, file := range info.Files {
	fmt.Printf("  %s (size: %d)\n", file.Path, file.Size)
}
Output:

type Props

type Props struct {
	Dir         string // Directory with files (for relative paths)
	File        string // Output file name
	IncludeFile string // File with include filenames
	Exclude     string // Exclude filenames
	ExcludeFile string // File with exclude filenames
	OutputDir   string // Output dir (for extract command)
	Password    string // Password
	WorkingDir  string // Working dir
	Compression int    // Compression level (0-9)
	Threads     int    // Number of CPU threads
	Recursive   bool   // Recurse subdirectories
	Delete      bool   // Delete files after compression
}

Props contains properties for packing/unpacking data

func (Props) ToArgs

func (p Props) ToArgs(command string) []string

ToArgs converts properties to p7zip arguments

func (Props) Validate

func (p Props) Validate(checkFile bool) error

Validate validates properties values

Jump to

Keyboard shortcuts

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