diff --git a/README.md b/README.md
index 0aaa0b9..221b299 100644
--- a/README.md
+++ b/README.md
@@ -1134,6 +1134,9 @@ var sh = fs.Shell();
* [sh.tempDir(callback)](#tempDir)
* [sh.mkdirp(path, callback)](#mkdirp)
* [sh.wget(path, [options], callback)](#wget)
+* [sh.zip(zipfile, paths, [options], callback)](#zip)
+* [sh.unzip(zipfile, [options], callback)](#unzip)
+
#### sh.cd(path, callback)
@@ -1364,3 +1367,60 @@ sh.wget('/files/file.json', {filename: 'file.json'}, function(err, path) {
// /file.json is now saved to the fs
});
```
+
+#### sh.zip(zipfile, paths, [options], callback)]
+
+Creates a zip archive named `zipfile` using the paths (files, dirs) listed in `paths`.
+Valid options include `recursive=true`, which when set, causes directories to be followed
+deeply. The `paths` argument must either be a single path (String) or a list of paths
+(Array of String). The zip archive file, named in `zipfile`, must not exist or an error
+will be returned on the callback. The callback receives `(error)`.
+
+Examples:
+
+```javascript
+// Compress a single file
+sh.zip('/data.zip', '/data.txt', function(err) {
+ if(err) throw err;
+ // /data.zip is now the compressed archive of /data.txt
+});
+
+// Compress multiple files
+sh.zip('/data.zip', ['/data.txt', '/data2.txt'], function(err) {
+ if(err) throw err;
+ // /data.zip is now the compressed archive of /data.txt and /data2.txt
+});
+
+// Compress the entire filesystem, starting at the root /
+sh.zip('/fs-backup.zip', '/', { recursive: true }, function(err) {
+ if(err) throw err;
+ // /fs-backup.zip now contains the entire filesystem
+});
+```
+
+#### sh.unzip(zipfile, [options], callback)]
+
+Extracts files and directories from a zip archive named `zipfile`. If `zipfile` does not
+exist, an error is returned on the callback. Valid options include `destination`, which
+is the path to use when extracting the files (defaults to the shell's current working directory).
+If an optional `destination` path is specified, it must first exist. The callback receives `(error)`.
+
+Examples:
+
+```javascript
+// Extract files in /backup.zip to the current directory
+sh.unzip('/backup.zip', function(err) {
+ if(err) throw err;
+ // The current working directory now contains all files archived in backup.zip
+});
+
+// Extract files in /backup.zip to the /backup directory
+sh.mkdirp('/backup', function(err) {
+ if(err) throw err;
+
+ sh.unzip('/backup.zip', { destination: '/backup' }, function(err) {
+ if(err) throw err;
+ // The current working directory now contains all files archived in backup.zip
+ });
+});
+```
diff --git a/src/shell/shell.js b/src/shell/shell.js
index f7e9439..0966fd2 100644
--- a/src/shell/shell.js
+++ b/src/shell/shell.js
@@ -479,7 +479,7 @@ define(function(require) {
request.send();
};
- Shell.prototype.unzip = function(path, options, callback) {
+ Shell.prototype.unzip = function(zipfile, options, callback) {
var fs = this.fs;
var sh = this;
if(typeof options === 'function') {
@@ -489,12 +489,12 @@ define(function(require) {
options = options || {};
callback = callback || function(){};
- if(!path) {
- callback(new Errors.EINVAL('missing path argument'));
+ if(!zipfile) {
+ callback(new Errors.EINVAL('missing zipfile argument'));
return;
}
- path = Path.resolve(this.cwd, path);
+ var path = Path.resolve(this.cwd, zipfile);
var destination = Path.resolve(options.destination || this.cwd);
fs.readFile(path, function(err, data) {
diff --git a/tests/spec/shell/unzip.spec.js b/tests/spec/shell/zip-unzip.spec.js
similarity index 100%
rename from tests/spec/shell/unzip.spec.js
rename to tests/spec/shell/zip-unzip.spec.js
diff --git a/tests/test-manifest.js b/tests/test-manifest.js
index a5c2a46..e6e7dd1 100644
--- a/tests/test-manifest.js
+++ b/tests/test-manifest.js
@@ -58,7 +58,7 @@ define([
"spec/shell/env.spec",
"spec/shell/mkdirp.spec",
"spec/shell/wget.spec",
- "spec/shell/unzip.spec",
+ "spec/shell/zip-unzip.spec",
// Ported node.js tests (filenames match names in https://github.com/joyent/node/tree/master/test)
"spec/node-js/simple/test-fs-mkdir",