Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

.functions: Improve `targz` #199

Closed
wants to merge 1 commit into from

1 participant

Mathias Bynens
Mathias Bynens

Idea: Would be cool if targz foo would create foo.tar, then check its file size, and then use it to decide wether to use zopfli or gzip. Anything over, say, 50 MB, should probably use gzip. Zopfli is great for small files, but quickly becomes too slow as file size increases.

@alrra suggested using fewer Zopfli iterations (15 is the default) but I’m not sure about that, as it would minimize the benefit of using Zopfli.

@einars suggested using pigz (brew install pigz), the fast gzip-compatible multithreaded compressor™. Perhaps another check before falling back to gzip?

Mathias Bynens mathiasbynens referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Mathias Bynens mathiasbynens referenced this pull request from a commit
Mathias Bynens .functions: Improve `targz`
* Only use `zopfli` when it’s available and if the `.tar` file is smaller than 50 MB.
* Use `pigz` instead of `gzip` when it’s available.
* Always exclude `.DS_Store` files when creating a tarball.

Closes #199.
78df21f
Mathias Bynens

I guess this is pretty much finalized. Just waiting for Homebrew/homebrew#19435 to be merged.

Mathias Bynens .functions: Improve `targz`
* Only use `zopfli` when it’s available and if the `.tar` file is smaller than 50 MB.
* Use `pigz` instead of `gzip` when it’s available.
* Always exclude `.DS_Store` files when creating a tarball.

Closes #199.
6e8b6a9
Mathias Bynens mathiasbynens closed this pull request from a commit
Mathias Bynens .functions: Improve `targz`
* Only use `zopfli` when it’s available and if the `.tar` file is smaller than 50 MB.
* Use `pigz` instead of `gzip` when it’s available.
* Always exclude `.DS_Store` files when creating a tarball.

Closes #199.
b53818f
Mathias Bynens mathiasbynens deleted the branch
Justin Yost jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Justin Yost jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Justin Yost jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Justin Yost jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Justin Yost jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Justin Yost jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Justin Yost jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Justin Yost jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Justin Yost jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
bdd desimone referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
bdd desimone referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sean Webster seandw referenced this pull request from a commit
Mathias Bynens .functions: Improve `targz`
* Only use `zopfli` when it’s available and if the `.tar` file is smaller than 50 MB.
* Use `pigz` instead of `gzip` when it’s available.
* Always exclude `.DS_Store` files when creating a tarball.

Closes #199.
8658d5a
Mark Norgren mrkd referenced this pull request from a commit in mrkd/dotfiles
Mathias Bynens .functions: Improve `targz`
* Only use `zopfli` when it’s available and if the `.tar` file is smaller than 50 MB.
* Use `pigz` instead of `gzip` when it’s available.
* Always exclude `.DS_Store` files when creating a tarball.

Closes #199.
8778b8d
Marcello di Simone MarcelloDiSimone referenced this pull request from a commit in MarcelloDiSimone/dotfiles
Mathias Bynens .functions: Improve `targz`
* Only use `zopfli` when it’s available and if the `.tar` file is smaller than 50 MB.
* Use `pigz` instead of `gzip` when it’s available.
* Always exclude `.DS_Store` files when creating a tarball.

Closes #199.
9c5335d
Thorsten Rinne thorsten referenced this pull request from a commit in thorsten/dotfiles
Mathias Bynens .functions: Improve `targz`
* Only use `zopfli` when it’s available and if the `.tar` file is smaller than 50 MB.
* Use `pigz` instead of `gzip` when it’s available.
* Always exclude `.DS_Store` files when creating a tarball.

Closes #199.
45c38cf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 1, 2013
  1. .functions: Improve `targz`

    authored
    * Only use `zopfli` when it’s available and if the `.tar` file is smaller than 50 MB.
    * Use `pigz` instead of `gzip` when it’s available.
    * Always exclude `.DS_Store` files when creating a tarball.
    
    Closes #199.
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 8 deletions.
  1. +2 −0  .brew
  2. +22 −8 .functions
2  .brew
View
@@ -39,10 +39,12 @@ brew install git
#brew install imagemagick
brew install lynx
brew install node
+brew install pigz
brew install rename
brew install rhino
brew install tree
brew install webkit2png
+brew install zopfli
brew tap homebrew/versions
brew install lua52
30 .functions
View
@@ -26,18 +26,32 @@ function cdf() { # short for `cdfinder`
cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')"
}
-# Create a .tar.gz archive, using `zopfli` or `gzip` for compression
+# Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression
function targz() {
- if zopfli > /dev/null 2>&1; then
+ local tmpFile="${@}.tar"
+ tar -cvf "${tmpFile}" --exclude=".DS_Store" "${@}" || return 1
+
+ size=$(
+ stat -f"%z" "${tmpFile}" 2> /dev/null; # OS X `stat`
+ stat -c"%s" "${tmpFile}" 2> /dev/null # GNU `stat`
+ )
+
+ local cmd=""
+ if (( size < 52428800 )) && hash zopfli 2> /dev/null; then
+ # the .tar file is smaller than 50 MB and Zopfli is available; use it
cmd="zopfli"
else
- cmd="gzip"
+ if hash pigz 2> /dev/null; then
+ cmd="pigz"
+ else
+ cmd="gzip"
+ fi
fi
- local tmpFile="${1}.tar"
- tar -cvf "${tmpFile}" "${1}" &&
- "${cmd}" "${tmpFile}" &&
- rm "${tmpFile}" 2> /dev/null &&
- echo "${tmpFile}.gz created successfully (compressed using \`${cmd}\`)."
+
+ echo "Compressing .tar using \`${cmd}\`…"
+ "${cmd}" -v "${tmpFile}" || return 1
+ [ -f "${tmpFile}" ] && rm "${tmpFile}"
+ echo "${tmpFile}.gz created successfully."
}
# Determine size of a file or total size of a directory
Something went wrong with that request. Please try again.