Remove absolute paths

This commit is contained in:
CrazyMax
2020-04-08 00:33:20 +02:00
parent ff47e64685
commit fce5f2e313
342 changed files with 6646 additions and 7223 deletions
+3 -23
View File
@@ -1,8 +1,7 @@
'use strict';
const fs = require('fs');
const path = require('path');
const url = require('url');
const caw = require('caw');
const {URL} = require('url');
const contentDisposition = require('content-disposition');
const archiveType = require('archive-type');
const decompress = require('decompress');
@@ -16,7 +15,7 @@ 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 filenameFromPath = res => path.basename(new URL(res.requestUrl).pathname);
const getExtFromMime = res => {
const header = res.headers['content-type'];
@@ -58,37 +57,18 @@ const getFilename = (res, data) => {
return filename;
};
const getProtocolFromUri = uri => {
let {protocol} = url.parse(uri);
if (protocol) {
protocol = protocol.slice(0, -1);
}
return protocol;
};
module.exports = (uri, output, opts) => {
if (typeof output === 'object') {
opts = output;
output = null;
}
const protocol = getProtocolFromUri(uri);
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))
.on('redirect', (response, nextOptions) => {
const redirectProtocol = getProtocolFromUri(nextOptions.href);
if (redirectProtocol && redirectProtocol !== protocol) {
nextOptions.agent = caw(opts.proxy, {protocol: redirectProtocol});
}
});
const stream = got.stream(uri, opts);
const promise = pEvent(stream, 'response').then(res => {
const encoding = opts.encoding === null ? 'buffer' : opts.encoding;
+21 -29
View File
@@ -1,32 +1,25 @@
{
"_args": [
[
"download@7.1.0",
"X:\\dev\\neard\\www\\github\\goreleaser\\goreleaser-action"
]
],
"_from": "download@7.1.0",
"_id": "download@7.1.0",
"_from": "download@8.0.0",
"_id": "download@8.0.0",
"_inBundle": false,
"_integrity": "sha512-xqnBTVd/E+GxJVrX5/eUJiLYjCGPwMpdL+jGhGU57BvtcA7wwhtHVbXBeUk51kOpW3S7Jn3BQbN9Q1R1Km2qDQ==",
"_integrity": "sha512-ASRY5QhDk7FK+XrQtQyvhpDKanLluEEQtWl/J7Lxuf/b+i8RYh997QeXvL85xitrmRKVlx9c7eTrcRdq2GS4eA==",
"_location": "/download",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "download@7.1.0",
"raw": "download@8.0.0",
"name": "download",
"escapedName": "download",
"rawSpec": "7.1.0",
"rawSpec": "8.0.0",
"saveSpec": null,
"fetchSpec": "7.1.0"
"fetchSpec": "8.0.0"
},
"_requiredBy": [
"/"
],
"_resolved": "https://registry.npmjs.org/download/-/download-7.1.0.tgz",
"_spec": "7.1.0",
"_where": "X:\\dev\\neard\\www\\github\\goreleaser\\goreleaser-action",
"_resolved": "https://registry.npmjs.org/download/-/download-8.0.0.tgz",
"_spec": "8.0.0",
"author": {
"name": "Kevin Mårtensson",
"email": "kevinmartensson@gmail.com",
@@ -37,30 +30,29 @@
},
"dependencies": {
"archive-type": "^4.0.0",
"caw": "^2.0.1",
"content-disposition": "^0.5.2",
"decompress": "^4.2.0",
"decompress": "^4.2.1",
"ext-name": "^5.0.0",
"file-type": "^8.1.0",
"filenamify": "^2.0.0",
"get-stream": "^3.0.0",
"file-type": "^11.1.0",
"filenamify": "^3.0.0",
"get-stream": "^4.1.0",
"got": "^8.3.1",
"make-dir": "^1.2.0",
"make-dir": "^2.1.0",
"p-event": "^2.1.0",
"pify": "^3.0.0"
"pify": "^4.0.1"
},
"description": "Download and extract files",
"devDependencies": {
"ava": "*",
"ava": "^1.4.1",
"is-zip": "^1.0.0",
"nock": "^9.2.5",
"nock": "^10.0.6",
"path-exists": "^3.0.0",
"random-buffer": "^0.1.0",
"rimraf": "^2.6.2",
"xo": "*"
"rimraf": "^3.0.0",
"xo": "^0.24.0"
},
"engines": {
"node": ">=6"
"node": ">=10"
},
"files": [
"index.js"
@@ -82,5 +74,5 @@
"scripts": {
"test": "xo && ava"
},
"version": "7.1.0"
}
"version": "8.0.0"
}
+14 -25
View File
@@ -18,28 +18,28 @@ $ npm install download
const fs = require('fs');
const download = require('download');
download('http://unicorn.com/foo.jpg', 'dist').then(() => {
console.log('done!');
});
(async () => {
await download('http://unicorn.com/foo.jpg', 'dist');
download('http://unicorn.com/foo.jpg').then(data => {
fs.writeFileSync('dist/foo.jpg', data);
});
fs.writeFileSync('dist/foo.jpg', await download('http://unicorn.com/foo.jpg'));
download('unicorn.com/foo.jpg').pipe(fs.createWriteStream('dist/foo.jpg'));
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!');
});
await Promise.all([
'unicorn.com/foo.jpg',
'cats.com/dancing.gif'
].map(url => download(url, 'dist')));
})();
```
### Proxies
To work with proxies, read the [`got documentation`](https://github.com/sindresorhus/got#proxies).
## API
### download(url, [destination], [options])
### 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-1).
@@ -73,14 +73,3 @@ If set to `true`, try extracting the file using [`decompress`](https://github.co
Type: `string`
Name of the saved file.
##### proxy
Type: `string`
Proxy endpoint.
## License
MIT © [Kevin Mårtensson](https://github.com/kevva)