first commit
This commit is contained in:
211
build/node_modules/download/index.js
generated
vendored
Normal file
211
build/node_modules/download/index.js
generated
vendored
Normal file
@@ -0,0 +1,211 @@
|
||||
'use strict';
|
||||
var path = require('path');
|
||||
var url = require('url');
|
||||
var caw = require('caw');
|
||||
var concatStream = require('concat-stream');
|
||||
var decompress = require('gulp-decompress');
|
||||
var eachAsync = require('each-async');
|
||||
var filenamify = require('filenamify');
|
||||
var got = require('got');
|
||||
var isUrl = require('is-url');
|
||||
var objectAssign = require('object-assign');
|
||||
var readAllStream = require('read-all-stream');
|
||||
var rename = require('gulp-rename');
|
||||
var streamCombiner = require('stream-combiner2');
|
||||
var PassThrough = require('readable-stream/passthrough');
|
||||
var Vinyl = require('vinyl');
|
||||
var vinylFs = require('vinyl-fs');
|
||||
var Ware = require('ware');
|
||||
|
||||
/**
|
||||
* Initialize a new `Download`
|
||||
*
|
||||
* @param {Object} opts
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function Download(opts) {
|
||||
if (!(this instanceof Download)) {
|
||||
return new Download(opts);
|
||||
}
|
||||
|
||||
this.opts = objectAssign({encoding: null}, opts);
|
||||
this.ware = new Ware();
|
||||
}
|
||||
|
||||
module.exports = Download;
|
||||
|
||||
/**
|
||||
* Get or set URL to download
|
||||
*
|
||||
* @param {String} url
|
||||
* @param {String} dest
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Download.prototype.get = function (url, dest) {
|
||||
if (!arguments.length) {
|
||||
return this._get;
|
||||
}
|
||||
|
||||
this._get = this._get || [];
|
||||
this._get.push({
|
||||
url: url,
|
||||
dest: dest
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get or set the destination folder
|
||||
*
|
||||
* @param {String} dir
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Download.prototype.dest = function (dir) {
|
||||
if (!arguments.length) {
|
||||
return this._dest;
|
||||
}
|
||||
|
||||
this._dest = dir;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Rename the downloaded file
|
||||
*
|
||||
* @param {Function|String} name
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Download.prototype.rename = function (name) {
|
||||
if (!arguments.length) {
|
||||
return this._rename;
|
||||
}
|
||||
|
||||
this._rename = name;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a plugin to the middleware stack
|
||||
*
|
||||
* @param {Function} plugin
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Download.prototype.use = function (plugin) {
|
||||
this.ware.use(plugin);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Run
|
||||
*
|
||||
* @param {Function} cb
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Download.prototype.run = function (cb) {
|
||||
cb = cb || function () {};
|
||||
var files = [];
|
||||
|
||||
eachAsync(this.get(), function (get, i, done) {
|
||||
if (!isUrl(get.url)) {
|
||||
done(new Error('Specify a valid URL'));
|
||||
return;
|
||||
}
|
||||
|
||||
var protocol = url.parse(get.url).protocol;
|
||||
if (protocol) {
|
||||
protocol = protocol.slice(0, -1);
|
||||
}
|
||||
var agent = caw(this.opts.proxy, {protocol: protocol});
|
||||
var stream = got.stream(get.url, objectAssign(this.opts, {agent: agent}));
|
||||
|
||||
stream.on('response', function (res) {
|
||||
stream.headers = res.headers;
|
||||
stream.statusCode = res.statusCode;
|
||||
this.ware.run(stream, get.url);
|
||||
}.bind(this));
|
||||
|
||||
var hasHttpError = false;
|
||||
|
||||
readAllStream(stream, null, function (err, data) {
|
||||
if (hasHttpError) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
if (err instanceof got.HTTPError) {
|
||||
hasHttpError = true;
|
||||
}
|
||||
|
||||
done(err);
|
||||
return;
|
||||
}
|
||||
|
||||
var dest = get.dest || this.dest();
|
||||
var fileStream = this.createStream(this.createFile(get.url, data), dest);
|
||||
|
||||
fileStream.on('error', done);
|
||||
fileStream.pipe(concatStream({encoding: 'object'}, function (items) {
|
||||
files = files.concat(items);
|
||||
done();
|
||||
}));
|
||||
}.bind(this));
|
||||
}.bind(this), function (err) {
|
||||
if (err) {
|
||||
cb(err);
|
||||
return;
|
||||
}
|
||||
|
||||
cb(null, files);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Create vinyl file
|
||||
*
|
||||
* @param {String} url
|
||||
* @param {Buffer} data
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Download.prototype.createFile = function (url, data) {
|
||||
return objectAssign(new Vinyl({
|
||||
contents: data,
|
||||
path: filenamify(path.basename(url))
|
||||
}), {url: url});
|
||||
};
|
||||
|
||||
/**
|
||||
* Create stream
|
||||
*
|
||||
* @param {Object} file
|
||||
* @param {String} dest
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Download.prototype.createStream = function (file, dest) {
|
||||
var stream = new PassThrough({objectMode: true});
|
||||
var streams = [stream];
|
||||
|
||||
stream.end(file);
|
||||
|
||||
if (this.opts.extract) {
|
||||
streams.push(decompress(this.opts));
|
||||
}
|
||||
|
||||
if (this.rename()) {
|
||||
streams.push(rename(this.rename()));
|
||||
}
|
||||
|
||||
if (dest) {
|
||||
streams.push(vinylFs.dest(dest, this.opts));
|
||||
}
|
||||
|
||||
return streamCombiner.obj(streams);
|
||||
};
|
||||
21
build/node_modules/download/license
generated
vendored
Normal file
21
build/node_modules/download/license
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Kevin Mårtensson <kevinmartensson@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
87
build/node_modules/download/package.json
generated
vendored
Normal file
87
build/node_modules/download/package.json
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"download@4.4.3",
|
||||
"/Users/asciidisco/Desktop/asciidisco.com/build"
|
||||
]
|
||||
],
|
||||
"_from": "download@4.4.3",
|
||||
"_id": "download@4.4.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-qlX9rTktldS2jowr4D4MKqIbqaw=",
|
||||
"_location": "/download",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "download@4.4.3",
|
||||
"name": "download",
|
||||
"escapedName": "download",
|
||||
"rawSpec": "4.4.3",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "4.4.3"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/bin-build",
|
||||
"/bin-wrapper"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/download/-/download-4.4.3.tgz",
|
||||
"_spec": "4.4.3",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build",
|
||||
"author": {
|
||||
"name": "Kevin Mårtensson",
|
||||
"email": "kevinmartensson@gmail.com",
|
||||
"url": "github.com/kevva"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/kevva/download/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"caw": "^1.0.1",
|
||||
"concat-stream": "^1.4.7",
|
||||
"each-async": "^1.0.0",
|
||||
"filenamify": "^1.0.1",
|
||||
"got": "^5.0.0",
|
||||
"gulp-decompress": "^1.2.0",
|
||||
"gulp-rename": "^1.2.0",
|
||||
"is-url": "^1.2.0",
|
||||
"object-assign": "^4.0.1",
|
||||
"read-all-stream": "^3.0.0",
|
||||
"readable-stream": "^2.0.2",
|
||||
"stream-combiner2": "^1.1.1",
|
||||
"vinyl": "^1.0.0",
|
||||
"vinyl-fs": "^2.2.0",
|
||||
"ware": "^1.2.0"
|
||||
},
|
||||
"description": "Download and extract files",
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"nock": "^3.1.0",
|
||||
"rimraf": "^2.2.8",
|
||||
"xo": "*"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/kevva/download#readme",
|
||||
"keywords": [
|
||||
"download",
|
||||
"extract",
|
||||
"http",
|
||||
"request",
|
||||
"url"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "download",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/kevva/download.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"version": "4.4.3"
|
||||
}
|
||||
124
build/node_modules/download/readme.md
generated
vendored
Normal file
124
build/node_modules/download/readme.md
generated
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
# download [](https://travis-ci.org/kevva/download)
|
||||
|
||||
> Download and extract files
|
||||
|
||||
*See [download-cli](https://github.com/kevva/download-cli) for the command-line version.*
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save download
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
If you're fetching an archive you can set `extract: true` in options and
|
||||
it'll extract it for you.
|
||||
|
||||
```js
|
||||
var Download = require('download');
|
||||
|
||||
new Download({mode: '755'})
|
||||
.get('http://example.com/foo.zip')
|
||||
.get('http://example.com/cat.jpg')
|
||||
.dest('dest')
|
||||
.run();
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### new Download(options)
|
||||
|
||||
Creates a new `Download` instance.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
Options for [`got`](https://github.com/sindresorhus/got) or the underlying [`http`](https://nodejs.org/api/http.html#http_http_request_options_callback)/[`https`](https://nodejs.org/api/https.html#https_https_request_options_callback) request can be specified,
|
||||
as well as options specific to the `download` module as described below.
|
||||
|
||||
##### options.extract
|
||||
|
||||
Type: `boolean`
|
||||
Default: `false`
|
||||
|
||||
If set to `true`, try extracting the file using [decompress](https://github.com/kevva/decompress/).
|
||||
|
||||
##### options.mode
|
||||
|
||||
Type: `string`
|
||||
|
||||
Set mode on the downloaded file, i.e `{mode: '755'}`.
|
||||
|
||||
##### options.strip
|
||||
|
||||
Type: `number`
|
||||
Default: `0`
|
||||
|
||||
Remove leading directory components from extracted files.
|
||||
|
||||
### .get(url, [dest])
|
||||
|
||||
#### url
|
||||
|
||||
Type: `string`
|
||||
|
||||
Add a URL to download.
|
||||
|
||||
#### dest
|
||||
|
||||
Type: `string`
|
||||
|
||||
Set an optional destination folder that will take precedence over the one set in
|
||||
`.dest()`.
|
||||
|
||||
### .dest(dir)
|
||||
|
||||
#### dir
|
||||
|
||||
Type: `string`
|
||||
|
||||
Set the destination folder to where your files will be downloaded.
|
||||
|
||||
### .rename(name)
|
||||
|
||||
#### name
|
||||
|
||||
Type: `function` or `string`
|
||||
|
||||
Rename your files using [gulp-rename](https://github.com/hparra/gulp-rename).
|
||||
|
||||
### .use(plugin)
|
||||
|
||||
#### plugin(response, url)
|
||||
|
||||
Type: `function`
|
||||
|
||||
Add a plugin to the middleware stack.
|
||||
|
||||
##### response
|
||||
|
||||
The [response object](http://nodejs.org/api/http.html#http_http_incomingmessage).
|
||||
|
||||
##### url
|
||||
|
||||
The requested URL.
|
||||
|
||||
### .run(callback)
|
||||
|
||||
#### callback(err, files)
|
||||
|
||||
Type: `function`
|
||||
|
||||
##### files
|
||||
|
||||
Contains an array of vinyl files.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Kevin Mårtensson](http://github.com/kevva)
|
||||
Reference in New Issue
Block a user