@xhmikosr/downloader 10.0.0 → 10.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +5 -5
- package/package.json +2 -9
package/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import filenamify from 'filenamify';
|
|
|
8
8
|
import getStream from 'get-stream';
|
|
9
9
|
import got from 'got';
|
|
10
10
|
import {pEvent} from 'p-event';
|
|
11
|
-
import
|
|
11
|
+
import fileType from 'file-type';
|
|
12
12
|
import extName from 'ext-name';
|
|
13
13
|
|
|
14
14
|
const filenameFromPath = res => path.basename(new URL(res.requestUrl).pathname);
|
|
@@ -29,7 +29,7 @@ const getExtFromMime = res => {
|
|
|
29
29
|
return exts[0].ext;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
const getFilename =
|
|
32
|
+
const getFilename = (res, data) => {
|
|
33
33
|
const header = res.headers['content-disposition'];
|
|
34
34
|
|
|
35
35
|
if (header) {
|
|
@@ -43,7 +43,7 @@ const getFilename = async (res, data) => {
|
|
|
43
43
|
let filename = filenameFromPath(res);
|
|
44
44
|
|
|
45
45
|
if (!path.extname(filename)) {
|
|
46
|
-
const ext = (
|
|
46
|
+
const ext = (fileType(data) || {}).ext || getExtFromMime(res);
|
|
47
47
|
|
|
48
48
|
if (ext) {
|
|
49
49
|
filename = `${filename}.${ext}`;
|
|
@@ -72,14 +72,14 @@ const download = (uri, output, options) => {
|
|
|
72
72
|
const promise = pEvent(stream, 'response').then(res => {
|
|
73
73
|
const encoding = options.responseType === 'buffer' ? 'buffer' : options.encoding;
|
|
74
74
|
return Promise.all([getStream(stream, {encoding}), res]);
|
|
75
|
-
}).then(
|
|
75
|
+
}).then(result => {
|
|
76
76
|
const [data, res] = result;
|
|
77
77
|
|
|
78
78
|
if (!output) {
|
|
79
79
|
return options.extract && archiveType(data) ? decompress(data, options) : data;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
const filename = options.filename || filenamify(
|
|
82
|
+
const filename = options.filename || filenamify(getFilename(res, data));
|
|
83
83
|
const outputFilepath = path.join(output, filename);
|
|
84
84
|
|
|
85
85
|
if (options.extract && archiveType(data)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xhmikosr/downloader",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.2",
|
|
4
4
|
"description": "Download and extract files",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "XhmikosR/download",
|
|
@@ -38,19 +38,12 @@
|
|
|
38
38
|
"request",
|
|
39
39
|
"url"
|
|
40
40
|
],
|
|
41
|
-
"c8": {
|
|
42
|
-
"reporter": [
|
|
43
|
-
"html",
|
|
44
|
-
"lcovonly",
|
|
45
|
-
"text"
|
|
46
|
-
]
|
|
47
|
-
},
|
|
48
41
|
"dependencies": {
|
|
49
42
|
"@xhmikosr/decompress": "^6.0.0",
|
|
50
43
|
"archive-type": "^4.0.0",
|
|
51
44
|
"content-disposition": "^0.5.4",
|
|
52
45
|
"ext-name": "^5.0.0",
|
|
53
|
-
"file-type": "^
|
|
46
|
+
"file-type": "^12.4.2",
|
|
54
47
|
"filenamify": "^5.1.1",
|
|
55
48
|
"get-stream": "^6.0.1",
|
|
56
49
|
"got": "^11.8.6",
|