Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Update docs and make couple other insignificant changes; move main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed Jul 3, 2016
1 parent fb2abc6 commit b74c2b4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
40 changes: 19 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
archiver [![archiver GoDoc](https://img.shields.io/badge/reference-godoc-blue.svg?style=flat-square)](https://godoc.org/github.com/mholt/archiver) [![Linux Build Status](https://img.shields.io/travis/mholt/archiver.svg?style=flat-square&label=linux+build)](https://travis-ci.org/mholt/archiver) [![Windows Build Status](https://img.shields.io/appveyor/ci/mholt/archiver.svg?style=flat-square&label=windows+build)](https://ci.appveyor.com/project/mholt/archiver)
========

Package archiver makes it trivially easy to make and extract .zip and .tar.gz files. Simply give the input and output file(s).
Package archiver makes it trivially easy to make and extract common archive formats such as .zip, .tar.gz, and .tar.bz2. Simply name the input and output file(s).

Files are put into the root of the archive; directories are recursively added.

The `archiver` command runs the same cross-platform and has no external dependencies (not even libc); powered by the Go standard library. Enjoy.
The `archiver` command runs the same cross-platform and has no external dependencies (not even libc); powered by the Go standard library and [dsnet/compress](https://github.com/dsnet/compress). Enjoy!

Supported formats/extensions:

- .zip
- .tar.gz (.tgz)
- .tar.bz2


## Install

```bash
go get github.com/mholt/archiver
go get github.com/mholt/cmd/archiver
```

Or download from the [releases](https://github.com/mholt/archiver/releases) page.
Or download binaries from the [releases](https://github.com/mholt/archiver/releases) page.


## Command Use
Expand All @@ -35,13 +41,15 @@ $ archiver open [archive name] [destination]

(The destination path is optional; default is current directory.)

The archive name must end with a supported file extension like .zip or .tar.gz—this is how it knows what kind of archive to make.


The archive name must end with a supported file extension—this is how it knows what kind of archive to make. Run `archiver -h` for more help.


## Library Use

```go
import "github.com/mholt/archiver"
```

Create a .zip file:

```go
Expand All @@ -54,27 +62,17 @@ Extract a .zip file:
err := archiver.Unzip("input.zip", "output_folder")
```

Create a .tar.gz file:

```go
err := archiver.TarGz("output.tar.gz", []string{"file.txt", "folder"})
```

Extract a .tar.gz file:

```go
err := archiver.UntarGz("input.tar.gz", "output_folder")
```
Working with other file formats is exactly the same, but with [their own functions](https://godoc.org/github.com/mholt/archiver).



## FAQ

#### Can I list a file to go in a different folder in the archive?
#### Can I list a file in one folder to go into a different folder in the archive?

No. Just structure your input files to mirror the structure you want in the archive, like you would normally do when you make an archive using your OS.
No. This works just like your OS would make an archive in Finder or File Explorer: organize your input files to mirror the structure you want in the archive.


#### Can it add files to an existing archive?

Nope. It's a simple tool; it just makes new archives or extracts existing ones.
Nope. This is a simple tool; it just makes new archives or extracts existing ones.
File renamed without changes.
16 changes: 10 additions & 6 deletions zip.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package archiver makes it super easy to create and open .zip and
// .tar.gz files.
// Package archiver makes it super easy to create and open .zip,
// .tar.gz, and .tar.bz2 files.
package archiver

import (
Expand Down Expand Up @@ -180,16 +180,19 @@ func mkdir(dirPath string) error {
return nil
}

// CompressedFormats is a set of lowercased file extensions
// for file formats that are typically already compressed.
// Compressing already-compressed files often results in
// a larger file. This list is not an exhaustive.
// CompressedFormats is a (non-exhaustive) set of lowercased
// file extensions for formats that are typically already
// compressed. Compressing already-compressed files often
// results in a larger file, so when possible, we check this
// set to avoid that.
var CompressedFormats = map[string]struct{}{
".7z": {},
".avi": {},
".bz2": {},
".cab": {},
".gif": {},
".gz": {},
".jar": {},
".jpeg": {},
".jpg": {},
".lz": {},
Expand All @@ -201,6 +204,7 @@ var CompressedFormats = map[string]struct{}{
".mpg": {},
".png": {},
".rar": {},
".tgz": {},
".xz": {},
".zip": {},
".zipx": {},
Expand Down

0 comments on commit b74c2b4

Please sign in to comment.