Skip to content

Instantly share code, notes, and snippets.

@sentientwaffle
Created February 9, 2012 17:32
Show Gist options
  • Save sentientwaffle/1781439 to your computer and use it in GitHub Desktop.
Save sentientwaffle/1781439 to your computer and use it in GitHub Desktop.
Node.js compress a directory with tar; and write it to a tmp dir.
###
Allow the user to download a file or a directory as a _.tar.gz_
compressed version.
###
fs = require "fs"
{exec} = require "child_process"
{resolve} = require "path"
# `callback` receives `(tarPath)`
module.exports = (path, callback) ->
fileName = path.split("/")
fileName = fileName[fileName.length - 1]
newPath = "./tmp/#{ fileName }.tar.gz"
exec "tar -czf '#{ newPath }' '#{ path }'",
(err, stdout, stderr) ->
throw err if err
callback newPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment