Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

.functions: Improve `targz` #199

Closed
wants to merge 1 commit into from

1 participant

@mathiasbynens

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?

@mathiasbynens mathiasbynens referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@mathiasbynens mathiasbynens referenced this pull request from a commit
@mathiasbynens .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
@mathiasbynens

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

@mathiasbynens .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
@mathiasbynens mathiasbynens closed this pull request from a commit
@mathiasbynens .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
@mathiasbynens mathiasbynens deleted the targz branch
@jtyost2 jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@jtyost2 jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@jtyost2 jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@jtyost2 jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@jtyost2 jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@jtyost2 jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@jtyost2 jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@jtyost2 jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@jtyost2 jtyost2 referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@desimone desimone referenced this pull request from a commit
@skwp skwp Disable bell [Fix #199] 7e23b64
@seandw seandw referenced this pull request from a commit
@mathiasbynens .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
@mrkd mrkd referenced this pull request from a commit in mrkd/dotfiles
@mathiasbynens .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
@MarcelloDiSimone MarcelloDiSimone referenced this pull request from a commit
@mathiasbynens .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 thorsten referenced this pull request from a commit in thorsten/dotfiles
@mathiasbynens .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
@dmcass dmcass referenced this pull request from a commit in dmcass/windows-dotfiles
@mathiasbynens .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.
d97d5c0
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
View
2  .brew
@@ -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
View
30 .functions
@@ -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.