Docs and update arg names to match docs
This commit is contained in:
parent
af4a004435
commit
411d6b2a9c
60
README.md
60
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)<a name="cd"></a>
|
||||
|
||||
|
@ -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)]<a name="zip"></a>
|
||||
|
||||
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)]<a name="zip"></a>
|
||||
|
||||
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
|
||||
});
|
||||
});
|
||||
```
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue