Categorygithub.com/keltia/archive
modulepackage
0.9.1
Repository: https://github.com/keltia/archive.git
Documentation: pkg.go.dev

# README

README.md

Status

GitHub release GitHub issues Go Version Build Status GoDoc SemVer License Go Report Card

Installation

As with many Go utilities, a simple

go get github.com/keltia/archive

is enough to fetch, build and install. Most of the time you will not need to do it explicitely, other applications will fetch it automatically as a dependency.

Dependencies

  • Go >= 1.10

Only standard Go modules are used. I use Semantic Versioning for all my modules.

Usage

The module currently supports the following "archives":

  • plain text
  • gzip files (one file per stream, only first stream)
  • zip files
  • GPG files (either .asc or .gpg)
  • Tar files
  • Zstd files (one file per stream, only first stream)

SYNOPSIS

    a, err := archive.New("foo.txt")
    content, err := a.Extract(".txt")
    
    a, err := archive.New("bar.zip")
    content, err := a.Extract(".txt")       // extract the first .txt file
    
    a, err := archive.New("baz.txt.gz")
    content, err := a.Extract(".txt")       // extracts baz.txt
    
    // Gpg is a bit special
    a, err := archive.New("xyz.zip.asc")
    unencrypted, err := a.Extract(".zip")   // decrypt into variable
                                            // if you want to use archive.New() there too
                                            // you need to save into a temp file.
    var buf bytes.Buffer
    
    fmt.Fprintf(&buf, "%s", unencrypted)                                        
    fh, err := os.Create("xyz.zip")
    _, err := io.Copy(fh, &buf)
    fh.Close()
    
    a1, err := archive.New("xyz.zip")
    ...
    You can have more verbose output and debug by using these functions:
    
    archive.SetVerbose()
    archive.SetDebug()      // implies verbose
    ...
    archive.Reset()         // both flags are cleared

Limitations

I wrote this both to simplify and my own code in dmarc-cat (that's also how sandbox got created) and to play with interfaces. It is currently only trying to extract one file at a time matching the extension provided. It will probably evolve into a more general code later.

Tests

I'm trying to get to 100% coverage but some error cases are more difficult to create.

License

This is released under the BSD 2-Clause license. See LICENSE.md.

Contributing

This project is an open Open Source project, please read CONTRIBUTING.md.

Feedback

We welcome pull requests, bug fixes and issue reports.

Before proposing a large change, first please discuss your change by raising an issue.

I use Git Flow for this package so please use something similar or the usual github workflow.

  1. Fork it ( https://github.com/keltia/archive/fork )
  2. Checkout the develop branch (git checkout develop)
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create a new Pull Request

# Functions

Ext2Type converts from string to archive type (int).
New is the main creator.
NewFromReader uses an io.Reader instead of a file.
NewGpgfile initializes the struct and check filename.
NewGzipfile stores the uncompressed file name.
No description provided by the author
No description provided by the author
NewZipfile open the zip file.
NewZstdfile stores the uncompressed file name.
Reset is for the two flags.
SetDebug sets the mode too.
SetVerbose sets the mode.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Version reports it.

# Constants

ArchiveGpg is for openpgp archives.
ArchiveGzip is for gzip archives.
ArchivePlain starts the different types.
ArchiveTar describes the tar ones.
ArchiveZip is for zip archives.
ArchiveZstd is for Zstd archives.

# Variables

No description provided by the author

# Structs

Gpg is how we use/mock decryption stuff.
Gpgme is for real gpgme stuff.
Gzip is a gzip-compressed file.
NullGPG is for testing.
No description provided by the author
Plain is for plain text.
Tar is a tar archive :).
Zip is for pkzip/infozip files.
Zstd is a gzip-compressed file.

# Interfaces

Decrypter is the gpgme interface.
ExtractCloser is the same with Close().
Extracter is the main interface we have.