@xhmikosr/downloader 9.0.0 → 10.0.0
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 +14 -11
- package/readme.md +1 -1
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 {fileTypeFromBuffer} 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 = (res, data) => {
|
|
32
|
+
const getFilename = async (res, data) => {
|
|
33
33
|
const header = res.headers['content-disposition'];
|
|
34
34
|
|
|
35
35
|
if (header) {
|
|
@@ -43,7 +43,7 @@ const getFilename = (res, data) => {
|
|
|
43
43
|
let filename = filenameFromPath(res);
|
|
44
44
|
|
|
45
45
|
if (!path.extname(filename)) {
|
|
46
|
-
const ext = (
|
|
46
|
+
const ext = (await fileTypeFromBuffer(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(result => {
|
|
75
|
+
}).then(async 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(getFilename(res, data));
|
|
82
|
+
const filename = options.filename || filenamify(await 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": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"description": "Download and extract files",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "XhmikosR/download",
|
|
@@ -10,16 +10,18 @@
|
|
|
10
10
|
"author": {
|
|
11
11
|
"email": "kevinmartensson@gmail.com",
|
|
12
12
|
"name": "Kevin Mårtensson",
|
|
13
|
-
"url": "github.com/kevva"
|
|
13
|
+
"url": "https://github.com/kevva"
|
|
14
14
|
},
|
|
15
15
|
"engines": {
|
|
16
|
-
"node": "^
|
|
16
|
+
"node": "^14.14.0 || >=16.0.0"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"ava": "ava",
|
|
20
|
+
"lint": "xo",
|
|
20
21
|
"xo": "xo",
|
|
22
|
+
"fix": "xo --fix",
|
|
21
23
|
"test": "npm run xo && npm run ava",
|
|
22
|
-
"test-ci": "
|
|
24
|
+
"test-ci": "c8 ava"
|
|
23
25
|
},
|
|
24
26
|
"main": "index.js",
|
|
25
27
|
"type": "module",
|
|
@@ -38,29 +40,30 @@
|
|
|
38
40
|
],
|
|
39
41
|
"c8": {
|
|
40
42
|
"reporter": [
|
|
43
|
+
"html",
|
|
41
44
|
"lcovonly",
|
|
42
45
|
"text"
|
|
43
46
|
]
|
|
44
47
|
},
|
|
45
48
|
"dependencies": {
|
|
46
|
-
"@xhmikosr/decompress": "^
|
|
49
|
+
"@xhmikosr/decompress": "^6.0.0",
|
|
47
50
|
"archive-type": "^4.0.0",
|
|
48
51
|
"content-disposition": "^0.5.4",
|
|
49
52
|
"ext-name": "^5.0.0",
|
|
50
|
-
"file-type": "^
|
|
53
|
+
"file-type": "^18.4.0",
|
|
51
54
|
"filenamify": "^5.1.1",
|
|
52
55
|
"get-stream": "^6.0.1",
|
|
53
|
-
"got": "^11.8.
|
|
56
|
+
"got": "^11.8.6",
|
|
54
57
|
"p-event": "^5.0.1"
|
|
55
58
|
},
|
|
56
59
|
"devDependencies": {
|
|
57
|
-
"ava": "^
|
|
58
|
-
"c8": "^7.
|
|
60
|
+
"ava": "^5.3.0",
|
|
61
|
+
"c8": "^7.13.0",
|
|
59
62
|
"is-zip": "^1.0.0",
|
|
60
|
-
"nock": "^13.
|
|
63
|
+
"nock": "^13.3.1",
|
|
61
64
|
"path-exists": "^5.0.0",
|
|
62
65
|
"random-buffer": "^0.1.0",
|
|
63
|
-
"xo": "^0.
|
|
66
|
+
"xo": "^0.54.2"
|
|
64
67
|
},
|
|
65
68
|
"xo": {
|
|
66
69
|
"rules": {
|
package/readme.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# download [](https://github.com/XhmikosR/download/actions/workflows/ci.yml)
|
|
1
|
+
# download [](https://github.com/XhmikosR/download/actions/workflows/ci.yml)
|
|
2
2
|
|
|
3
3
|
> Download and extract files
|
|
4
4
|
|