Created
February 9, 2012 17:32
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
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