First commit
This commit is contained in:
108
hGameTest/node_modules/download/index.js
generated
vendored
Normal file
108
hGameTest/node_modules/download/index.js
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const url = require('url');
|
||||
const caw = require('caw');
|
||||
const contentDisposition = require('content-disposition');
|
||||
const decompress = require('decompress');
|
||||
const filenamify = require('filenamify');
|
||||
const getStream = require('get-stream');
|
||||
const got = require('got');
|
||||
const makeDir = require('make-dir');
|
||||
const pify = require('pify');
|
||||
const pEvent = require('p-event');
|
||||
const fileType = require('file-type');
|
||||
const extName = require('ext-name');
|
||||
|
||||
const fsP = pify(fs);
|
||||
const filenameFromPath = res => path.basename(url.parse(res.requestUrl).pathname);
|
||||
|
||||
const getExtFromMime = res => {
|
||||
const header = res.headers['content-type'];
|
||||
|
||||
if (!header) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const exts = extName.mime(header);
|
||||
|
||||
if (exts.length !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return exts[0].ext;
|
||||
};
|
||||
|
||||
const getFilename = (res, data) => {
|
||||
const header = res.headers['content-disposition'];
|
||||
|
||||
if (header) {
|
||||
const parsed = contentDisposition.parse(header);
|
||||
|
||||
if (parsed.parameters && parsed.parameters.filename) {
|
||||
return parsed.parameters.filename;
|
||||
}
|
||||
}
|
||||
|
||||
let filename = filenameFromPath(res);
|
||||
|
||||
if (!path.extname(filename)) {
|
||||
const ext = (fileType(data) || {}).ext || getExtFromMime(res);
|
||||
|
||||
if (ext) {
|
||||
filename = `${filename}.${ext}`;
|
||||
}
|
||||
}
|
||||
|
||||
return filename;
|
||||
};
|
||||
|
||||
module.exports = (uri, output, opts) => {
|
||||
if (typeof output === 'object') {
|
||||
opts = output;
|
||||
output = null;
|
||||
}
|
||||
|
||||
let protocol = url.parse(uri).protocol;
|
||||
|
||||
if (protocol) {
|
||||
protocol = protocol.slice(0, -1);
|
||||
}
|
||||
|
||||
opts = Object.assign({
|
||||
encoding: null,
|
||||
rejectUnauthorized: process.env.npm_config_strict_ssl !== 'false'
|
||||
}, opts);
|
||||
|
||||
const agent = caw(opts.proxy, {protocol});
|
||||
const stream = got.stream(uri, Object.assign({agent}, opts));
|
||||
|
||||
const promise = pEvent(stream, 'response').then(res => {
|
||||
const encoding = opts.encoding === null ? 'buffer' : opts.encoding;
|
||||
return Promise.all([getStream(stream, {encoding}), res]);
|
||||
}).then(result => {
|
||||
// TODO: Use destructuring when targeting Node.js 6
|
||||
const data = result[0];
|
||||
const res = result[1];
|
||||
|
||||
if (!output) {
|
||||
return opts.extract ? decompress(data, opts) : data;
|
||||
}
|
||||
|
||||
const filename = opts.filename || filenamify(getFilename(res, data));
|
||||
const outputFilepath = path.join(output, filename);
|
||||
|
||||
if (opts.extract) {
|
||||
return decompress(data, path.dirname(outputFilepath), opts);
|
||||
}
|
||||
|
||||
return makeDir(path.dirname(outputFilepath))
|
||||
.then(() => fsP.writeFile(outputFilepath, data))
|
||||
.then(() => data);
|
||||
});
|
||||
|
||||
stream.then = promise.then.bind(promise);
|
||||
stream.catch = promise.catch.bind(promise);
|
||||
|
||||
return stream;
|
||||
};
|
||||
21
hGameTest/node_modules/download/license
generated
vendored
Normal file
21
hGameTest/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.
|
||||
82
hGameTest/node_modules/download/package.json
generated
vendored
Normal file
82
hGameTest/node_modules/download/package.json
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"_from": "download@^6.2.5",
|
||||
"_id": "download@6.2.5",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-DpO9K1sXAST8Cpzb7kmEhogJxymyVUd5qz/vCOSyvwtp2Klj2XcDt5YUuasgxka44SxF0q5RriKIwJmQHG2AuA==",
|
||||
"_location": "/download",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "download@^6.2.5",
|
||||
"name": "download",
|
||||
"escapedName": "download",
|
||||
"rawSpec": "^6.2.5",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^6.2.5"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/haxe"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/download/-/download-6.2.5.tgz",
|
||||
"_shasum": "acd6a542e4cd0bb42ca70cfc98c9e43b07039714",
|
||||
"_spec": "download@^6.2.5",
|
||||
"_where": "/home/andreas/Documents/Projects/haxe/openfl/nigger/node_modules/haxe",
|
||||
"author": {
|
||||
"name": "Kevin Mårtensson",
|
||||
"email": "kevinmartensson@gmail.com",
|
||||
"url": "github.com/kevva"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/kevva/download/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"caw": "^2.0.0",
|
||||
"content-disposition": "^0.5.2",
|
||||
"decompress": "^4.0.0",
|
||||
"ext-name": "^5.0.0",
|
||||
"file-type": "5.2.0",
|
||||
"filenamify": "^2.0.0",
|
||||
"get-stream": "^3.0.0",
|
||||
"got": "^7.0.0",
|
||||
"make-dir": "^1.0.0",
|
||||
"p-event": "^1.0.0",
|
||||
"pify": "^3.0.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Download and extract files",
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"is-zip": "^1.0.0",
|
||||
"nock": "^9.0.2",
|
||||
"path-exists": "^3.0.0",
|
||||
"random-buffer": "^0.1.0",
|
||||
"rimraf": "^2.2.8",
|
||||
"xo": "*"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"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": "6.2.5"
|
||||
}
|
||||
84
hGameTest/node_modules/download/readme.md
generated
vendored
Normal file
84
hGameTest/node_modules/download/readme.md
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
# 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
|
||||
|
||||
```js
|
||||
const fs = require('fs');
|
||||
const download = require('download');
|
||||
|
||||
download('http://unicorn.com/foo.jpg', 'dist').then(() => {
|
||||
console.log('done!');
|
||||
});
|
||||
|
||||
download('http://unicorn.com/foo.jpg').then(data => {
|
||||
fs.writeFileSync('dist/foo.jpg', data);
|
||||
});
|
||||
|
||||
download('unicorn.com/foo.jpg').pipe(fs.createWriteStream('dist/foo.jpg'));
|
||||
|
||||
Promise.all([
|
||||
'unicorn.com/foo.jpg',
|
||||
'cats.com/dancing.gif'
|
||||
].map(x => download(x, 'dist'))).then(() => {
|
||||
console.log('files downloaded!');
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### download(url, [destination], [options])
|
||||
|
||||
Returns both a `Promise<Buffer>` and a [Duplex stream](https://nodejs.org/api/stream.html#stream_class_stream_duplex) with [additional events](https://github.com/sindresorhus/got#streams).
|
||||
|
||||
#### url
|
||||
|
||||
Type: `string`
|
||||
|
||||
URL to download.
|
||||
|
||||
#### destination
|
||||
|
||||
Type: `string`
|
||||
|
||||
Path to where your file will be written.
|
||||
|
||||
#### options
|
||||
|
||||
Same options as [`got`](https://github.com/sindresorhus/got) in addition to the ones below.
|
||||
|
||||
##### extract
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
If set to `true`, try extracting the file using [`decompress`](https://github.com/kevva/decompress).
|
||||
|
||||
##### filename
|
||||
|
||||
Type: `string`
|
||||
|
||||
Name of the saved file.
|
||||
|
||||
##### proxy
|
||||
|
||||
Type: `string`
|
||||
|
||||
Proxy endpoint.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Kevin Mårtensson](https://github.com/kevva)
|
||||
Reference in New Issue
Block a user