@xhmikosr/downloader 13.0.0 → 14.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.
Files changed (2) hide show
  1. package/index.js +22 -15
  2. package/package.json +11 -12
package/index.js CHANGED
@@ -1,17 +1,26 @@
1
+ import events from 'node:events';
1
2
  import fs from 'node:fs/promises';
2
3
  import path from 'node:path';
3
4
  import process from 'node:process';
4
5
  import contentDisposition from 'content-disposition';
5
6
  import archiveType from '@xhmikosr/archive-type';
6
7
  import decompress from '@xhmikosr/decompress';
8
+ import defaults from 'defaults';
7
9
  import extName from 'ext-name';
8
10
  import {fileTypeFromBuffer} from 'file-type';
9
11
  import filenamify from 'filenamify';
10
12
  import getStream from 'get-stream';
11
13
  import got from 'got';
12
- // TODO replace with `defaults` package when we drop Node.js < 16 support
13
- import mergeOptions from 'merge-options';
14
- import {pEvent} from 'p-event';
14
+
15
+ const defaultOptions = {
16
+ got: {
17
+ responseType: 'buffer',
18
+ https: {
19
+ rejectUnauthorized: process.env.npm_config_strict_ssl !== 'false',
20
+ },
21
+ },
22
+ decompress: {},
23
+ };
15
24
 
16
25
  const getExtFromMime = response => {
17
26
  const header = response.headers['content-type'];
@@ -50,27 +59,25 @@ const getFilename = async (response, data) => {
50
59
  return filename;
51
60
  };
52
61
 
62
+ const filterEvents = async (name, listener) => {
63
+ for await (const [message] of events.on(name, listener)) {
64
+ if (message) {
65
+ return message;
66
+ }
67
+ }
68
+ };
69
+
53
70
  const download = (uri, output, options) => {
54
71
  if (typeof output === 'object') {
55
72
  options = output;
56
73
  output = null;
57
74
  }
58
75
 
59
- const defaultOptions = {
60
- got: {
61
- responseType: 'buffer',
62
- https: {
63
- rejectUnauthorized: process.env.npm_config_strict_ssl !== 'false',
64
- },
65
- },
66
- decompress: {},
67
- };
68
-
69
- options = mergeOptions(defaultOptions, options);
76
+ options = defaults(options, defaultOptions);
70
77
 
71
78
  const stream = got.stream(uri, options.got);
72
79
 
73
- const promise = pEvent(stream, 'response')
80
+ const promise = filterEvents(stream, 'response')
74
81
  .then(response => {
75
82
  const encoding = options.got.responseType === 'buffer' ? 'buffer' : options.got.encoding;
76
83
  return Promise.all([getStream(stream, {encoding}), response]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xhmikosr/downloader",
3
- "version": "13.0.0",
3
+ "version": "14.0.0",
4
4
  "description": "Download and extract files",
5
5
  "license": "MIT",
6
6
  "repository": "XhmikosR/download",
@@ -13,7 +13,7 @@
13
13
  "url": "https://github.com/kevva"
14
14
  },
15
15
  "engines": {
16
- "node": "^14.14.0 || >=16.0.0"
16
+ "node": ">=16"
17
17
  },
18
18
  "scripts": {
19
19
  "ava": "ava",
@@ -40,23 +40,22 @@
40
40
  ],
41
41
  "dependencies": {
42
42
  "@xhmikosr/archive-type": "^6.0.1",
43
- "@xhmikosr/decompress": "^9.0.0",
43
+ "@xhmikosr/decompress": "^9.0.1",
44
44
  "content-disposition": "^0.5.4",
45
+ "defaults": "^2.0.2",
45
46
  "ext-name": "^5.0.0",
46
- "file-type": "^18.5.0",
47
- "filenamify": "^5.1.1",
47
+ "file-type": "^18.7.0",
48
+ "filenamify": "^6.0.0",
48
49
  "get-stream": "^6.0.1",
49
- "got": "^12.6.1",
50
- "merge-options": "^3.0.4",
51
- "p-event": "^5.0.1"
50
+ "got": "^13.0.0"
52
51
  },
53
52
  "devDependencies": {
54
- "ava": "^4.3.3",
55
- "c8": "^8.0.0",
53
+ "ava": "^5.3.1",
54
+ "c8": "^8.0.1",
56
55
  "is-zip": "^1.0.0",
57
- "nock": "^13.3.1",
56
+ "nock": "^13.4.0",
58
57
  "path-exists": "^5.0.0",
59
- "xo": "^0.54.2"
58
+ "xo": "^0.56.0"
60
59
  },
61
60
  "xo": {
62
61
  "rules": {