@ethersphere/bee-js 3.3.0 → 3.3.1

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 (85) hide show
  1. package/dist/cjs/chunk/bmt.js +7 -2
  2. package/dist/cjs/chunk/signer.js +9 -4
  3. package/dist/cjs/modules/debug/status.js +5 -5
  4. package/dist/cjs/package.json +1 -0
  5. package/dist/cjs/types/ky-options.js +8 -0
  6. package/dist/cjs/types/ky-universal/common.js +8 -0
  7. package/dist/cjs/types/ky-universal/hooks.js +8 -0
  8. package/dist/cjs/types/ky-universal/retry.js +8 -0
  9. package/dist/cjs/utils/eth.js +8 -3
  10. package/dist/cjs/utils/hash.js +7 -2
  11. package/dist/cjs/utils/stream.js +14 -5
  12. package/dist/index.browser.min.js +3 -0
  13. package/dist/index.browser.min.js.LICENSE.txt +52 -0
  14. package/dist/index.browser.min.js.map +1 -0
  15. package/dist/mjs/bee-debug.js +608 -508
  16. package/dist/mjs/bee.js +935 -836
  17. package/dist/mjs/chunk/bmt.js +34 -24
  18. package/dist/mjs/chunk/cac.js +24 -22
  19. package/dist/mjs/chunk/serialize.js +9 -9
  20. package/dist/mjs/chunk/signer.js +92 -73
  21. package/dist/mjs/chunk/soc.js +78 -66
  22. package/dist/mjs/chunk/span.js +19 -16
  23. package/dist/mjs/feed/index.js +110 -101
  24. package/dist/mjs/feed/json.js +21 -17
  25. package/dist/mjs/feed/topic.js +18 -17
  26. package/dist/mjs/feed/type.js +5 -5
  27. package/dist/mjs/index.js +7 -7
  28. package/dist/mjs/modules/bytes.js +33 -30
  29. package/dist/mjs/modules/bzz.js +80 -77
  30. package/dist/mjs/modules/chunk.js +22 -20
  31. package/dist/mjs/modules/debug/balance.js +26 -22
  32. package/dist/mjs/modules/debug/chequebook.js +84 -65
  33. package/dist/mjs/modules/debug/chunk.js +15 -13
  34. package/dist/mjs/modules/debug/connectivity.js +34 -34
  35. package/dist/mjs/modules/debug/settlements.js +14 -12
  36. package/dist/mjs/modules/debug/stamps.js +52 -47
  37. package/dist/mjs/modules/debug/states.js +16 -14
  38. package/dist/mjs/modules/debug/status.js +55 -35
  39. package/dist/mjs/modules/debug/tag.js +8 -7
  40. package/dist/mjs/modules/debug/transactions.js +31 -25
  41. package/dist/mjs/modules/feed.js +39 -33
  42. package/dist/mjs/modules/pinning.js +34 -28
  43. package/dist/mjs/modules/pss.js +18 -14
  44. package/dist/mjs/modules/soc.js +18 -15
  45. package/dist/mjs/modules/status.js +6 -5
  46. package/dist/mjs/modules/stewardship.js +13 -12
  47. package/dist/mjs/modules/tag.js +38 -30
  48. package/dist/mjs/package.json +1 -0
  49. package/dist/mjs/types/debug.js +5 -4
  50. package/dist/mjs/types/index.js +6 -2
  51. package/dist/mjs/types/ky-options.js +7 -0
  52. package/dist/mjs/types/ky-universal/common.js +7 -0
  53. package/dist/mjs/types/ky-universal/hooks.js +7 -0
  54. package/dist/mjs/types/ky-universal/retry.js +7 -0
  55. package/dist/mjs/utils/bytes.js +32 -26
  56. package/dist/mjs/utils/collection.browser.js +4 -3
  57. package/dist/mjs/utils/collection.js +47 -35
  58. package/dist/mjs/utils/collection.node.js +53 -42
  59. package/dist/mjs/utils/data.browser.js +64 -48
  60. package/dist/mjs/utils/data.js +29 -25
  61. package/dist/mjs/utils/error.js +47 -39
  62. package/dist/mjs/utils/eth.js +119 -104
  63. package/dist/mjs/utils/expose.js +9 -9
  64. package/dist/mjs/utils/file.js +22 -19
  65. package/dist/mjs/utils/hash.js +10 -5
  66. package/dist/mjs/utils/headers.js +43 -39
  67. package/dist/mjs/utils/hex.js +78 -63
  68. package/dist/mjs/utils/http.js +119 -100
  69. package/dist/mjs/utils/merge.js +26 -20
  70. package/dist/mjs/utils/pss.js +8 -6
  71. package/dist/mjs/utils/stamps.js +7 -3
  72. package/dist/mjs/utils/stream.js +107 -82
  73. package/dist/mjs/utils/tar.js +17 -14
  74. package/dist/mjs/utils/type.js +249 -209
  75. package/dist/mjs/utils/uint64.js +16 -16
  76. package/dist/mjs/utils/url.js +32 -25
  77. package/dist/types/types/index.d.ts +1 -1
  78. package/dist/types/types/ky-options.d.ts +221 -0
  79. package/dist/types/types/ky-universal/common.d.ts +13 -0
  80. package/dist/types/types/ky-universal/hooks.d.ts +92 -0
  81. package/dist/types/types/ky-universal/retry.d.ts +38 -0
  82. package/dist/types/utils/stream.d.ts +11 -8
  83. package/package.json +9 -6
  84. package/dist/index.js +0 -28326
  85. package/dist/index.js.map +0 -1
@@ -1,17 +1,18 @@
1
- import { http } from '../utils/http';
1
+ import { http } from "../utils/http.js";
2
2
  const endpoint = 'tags';
3
3
  /**
4
4
  * Create new tag on the Bee node
5
5
  *
6
6
  * @param url Bee tag URL
7
7
  */
8
+
8
9
  export async function createTag(ky) {
9
- const response = await http(ky, {
10
- method: 'post',
11
- path: endpoint,
12
- responseType: 'json',
13
- });
14
- return response.data;
10
+ const response = await http(ky, {
11
+ method: 'post',
12
+ path: endpoint,
13
+ responseType: 'json'
14
+ });
15
+ return response.data;
15
16
  }
16
17
  /**
17
18
  * Retrieve tag information from Bee node
@@ -19,12 +20,13 @@ export async function createTag(ky) {
19
20
  * @param url Bee tag URL
20
21
  * @param uid UID of tag to be retrieved
21
22
  */
23
+
22
24
  export async function retrieveTag(ky, uid) {
23
- const response = await http(ky, {
24
- path: `${endpoint}/${uid}`,
25
- responseType: 'json',
26
- });
27
- return response.data;
25
+ const response = await http(ky, {
26
+ path: `${endpoint}/${uid}`,
27
+ responseType: 'json'
28
+ });
29
+ return response.data;
28
30
  }
29
31
  /**
30
32
  * Get limited listing of all tags.
@@ -33,24 +35,29 @@ export async function retrieveTag(ky, uid) {
33
35
  * @param offset
34
36
  * @param limit
35
37
  */
38
+
36
39
  export async function getAllTags(ky, offset, limit) {
37
- const response = await http(ky, {
38
- path: `${endpoint}`,
39
- searchParams: { offset, limit },
40
- responseType: 'json',
41
- });
42
- return response.data.tags;
40
+ const response = await http(ky, {
41
+ path: `${endpoint}`,
42
+ searchParams: {
43
+ offset,
44
+ limit
45
+ },
46
+ responseType: 'json'
47
+ });
48
+ return response.data.tags;
43
49
  }
44
50
  /**
45
51
  * Removes tag from the Bee node.
46
52
  * @param url
47
53
  * @param uid
48
54
  */
55
+
49
56
  export async function deleteTag(ky, uid) {
50
- await http(ky, {
51
- method: 'delete',
52
- path: `${endpoint}/${uid}`,
53
- });
57
+ await http(ky, {
58
+ method: 'delete',
59
+ path: `${endpoint}/${uid}`
60
+ });
54
61
  }
55
62
  /**
56
63
  * Updates tag
@@ -58,12 +65,13 @@ export async function deleteTag(ky, uid) {
58
65
  * @param uid
59
66
  * @param reference
60
67
  */
68
+
61
69
  export async function updateTag(ky, uid, reference) {
62
- await http(ky, {
63
- method: 'patch',
64
- path: `${endpoint}/${uid}`,
65
- json: {
66
- reference,
67
- },
68
- });
69
- }
70
+ await http(ky, {
71
+ method: 'patch',
72
+ path: `${endpoint}/${uid}`,
73
+ json: {
74
+ reference
75
+ }
76
+ });
77
+ }
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "browser": {
4
+ "stream": false,
4
5
  "./utils/data.js": "./utils/data.browser.js",
5
6
  "./utils/collection.node.js": "./utils/collection.browser.js"
6
7
  }
@@ -1,6 +1,7 @@
1
1
  export var BeeModes;
2
+
2
3
  (function (BeeModes) {
3
- BeeModes["FULL"] = "full";
4
- BeeModes["LIGHT"] = "light";
5
- BeeModes["DEV"] = "dev";
6
- })(BeeModes || (BeeModes = {}));
4
+ BeeModes["FULL"] = "full";
5
+ BeeModes["LIGHT"] = "light";
6
+ BeeModes["DEV"] = "dev";
7
+ })(BeeModes || (BeeModes = {}));
@@ -1,4 +1,4 @@
1
- export * from './debug';
1
+ export * from "./debug.js";
2
2
  export const SPAN_SIZE = 8;
3
3
  export const SECTION_SIZE = 32;
4
4
  export const BRANCHES = 128;
@@ -14,20 +14,24 @@ export const ENCRYPTED_REFERENCE_BYTES_LENGTH = 64;
14
14
  /**
15
15
  * Minimal depth that can be used for creation of postage batch
16
16
  */
17
+
17
18
  export const STAMPS_DEPTH_MIN = 17;
18
19
  /**
19
20
  * Maximal depth that can be used for creation of postage batch
20
21
  */
22
+
21
23
  export const STAMPS_DEPTH_MAX = 255;
22
24
  export const TAGS_LIMIT_MIN = 1;
23
25
  export const TAGS_LIMIT_MAX = 1000;
24
26
  /*********************************************************
25
27
  * Writers and Readers interfaces
26
28
  */
29
+
27
30
  export const TOPIC_BYTES_LENGTH = 32;
28
31
  export const TOPIC_HEX_LENGTH = 64;
29
32
  /*********************************************************
30
33
  * Ethereum compatible signing interfaces and definitions
31
34
  */
35
+
32
36
  export const SIGNATURE_HEX_LENGTH = 130;
33
- export const SIGNATURE_BYTES_LENGTH = 65;
37
+ export const SIGNATURE_BYTES_LENGTH = 65;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Types extracted from Ky as a backport for older Ky non-ESM version
3
+ *
4
+ * @author https://github.com/sindresorhus
5
+ * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
6
+ */
7
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Types extracted from Ky as a backport for older Ky non-ESM version
3
+ *
4
+ * @author https://github.com/sindresorhus
5
+ * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
6
+ */
7
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Types extracted from Ky as a backport for older Ky non-ESM version
3
+ *
4
+ * @author https://github.com/sindresorhus
5
+ * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
6
+ */
7
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Types extracted from Ky as a backport for older Ky non-ESM version
3
+ *
4
+ * @author https://github.com/sindresorhus
5
+ * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
6
+ */
7
+ export {};
@@ -1,12 +1,13 @@
1
- import { bytesToHex } from './hex';
1
+ import { bytesToHex } from "./hex.js";
2
2
  /**
3
3
  * Type guard for `Bytes<T>` type
4
4
  *
5
5
  * @param b The byte array
6
6
  * @param length The length of the byte array
7
7
  */
8
+
8
9
  export function isBytes(b, length) {
9
- return b instanceof Uint8Array && b.length === length;
10
+ return b instanceof Uint8Array && b.length === length;
10
11
  }
11
12
  /**
12
13
  * Verifies if a byte array has a certain length
@@ -14,10 +15,11 @@ export function isBytes(b, length) {
14
15
  * @param b The byte array
15
16
  * @param length The specified length
16
17
  */
18
+
17
19
  export function assertBytes(b, length) {
18
- if (!isBytes(b, length)) {
19
- throw new TypeError(`Parameter is not valid Bytes of length: ${length} !== ${b.length}`);
20
- }
20
+ if (!isBytes(b, length)) {
21
+ throw new TypeError(`Parameter is not valid Bytes of length: ${length} !== ${b.length}`);
22
+ }
21
23
  }
22
24
  /**
23
25
  * Type guard for FlexBytes<Min,Max> type
@@ -26,8 +28,9 @@ export function assertBytes(b, length) {
26
28
  * @param min Minimum size of the array
27
29
  * @param max Maximum size of the array
28
30
  */
31
+
29
32
  export function isFlexBytes(b, min, max) {
30
- return b instanceof Uint8Array && b.length >= min && b.length <= max;
33
+ return b instanceof Uint8Array && b.length >= min && b.length <= max;
31
34
  }
32
35
  /**
33
36
  * Verifies if a byte array has a certain length between min and max
@@ -36,10 +39,11 @@ export function isFlexBytes(b, min, max) {
36
39
  * @param min Minimum size of the array
37
40
  * @param max Maximum size of the array
38
41
  */
42
+
39
43
  export function assertFlexBytes(b, min, max) {
40
- if (!isFlexBytes(b, min, max)) {
41
- throw new TypeError(`Parameter is not valid FlexBytes of min: ${min}, max: ${max}, length: ${b.length}`);
42
- }
44
+ if (!isFlexBytes(b, min, max)) {
45
+ throw new TypeError(`Parameter is not valid FlexBytes of min: ${min}, max: ${max}, length: ${b.length}`);
46
+ }
43
47
  }
44
48
  /**
45
49
  * Return `length` bytes starting from `offset`
@@ -48,11 +52,12 @@ export function assertFlexBytes(b, min, max) {
48
52
  * @param offset The offset to start from
49
53
  * @param length The length of data to be returned
50
54
  */
55
+
51
56
  export function bytesAtOffset(data, offset, length) {
52
- const offsetBytes = data.slice(offset, offset + length);
53
- // We are returning strongly typed Bytes so we have to verify that length is really what we claim
54
- assertBytes(offsetBytes, length);
55
- return offsetBytes;
57
+ const offsetBytes = data.slice(offset, offset + length); // We are returning strongly typed Bytes so we have to verify that length is really what we claim
58
+
59
+ assertBytes(offsetBytes, length);
60
+ return offsetBytes;
56
61
  }
57
62
  /**
58
63
  * Return flex bytes starting from `offset`
@@ -62,12 +67,11 @@ export function bytesAtOffset(data, offset, length) {
62
67
  * @param _min The minimum size of the data
63
68
  * @param _max The maximum size of the data
64
69
  */
65
- export function flexBytesAtOffset(data, offset,
66
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
67
- _min,
68
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
70
+
71
+ export function flexBytesAtOffset(data, offset, // eslint-disable-next-line @typescript-eslint/no-unused-vars
72
+ _min, // eslint-disable-next-line @typescript-eslint/no-unused-vars
69
73
  _max) {
70
- return data.slice(offset);
74
+ return data.slice(offset);
71
75
  }
72
76
  /**
73
77
  * Returns true if two byte arrays are equal
@@ -75,21 +79,23 @@ _max) {
75
79
  * @param a Byte array to compare
76
80
  * @param b Byte array to compare
77
81
  */
82
+
78
83
  export function bytesEqual(a, b) {
79
- return a.length === b.length && a.every((value, index) => value === b[index]);
84
+ return a.length === b.length && a.every((value, index) => value === b[index]);
80
85
  }
81
86
  /**
82
87
  * Returns a new byte array filled with zeroes with the specified length
83
88
  *
84
89
  * @param length The length of data to be returned
85
90
  */
91
+
86
92
  export function makeBytes(length) {
87
- return new Uint8Array(length);
93
+ return new Uint8Array(length);
88
94
  }
89
95
  export function wrapBytesWithHelpers(data) {
90
- return Object.assign(data, {
91
- text: () => new TextDecoder('utf-8').decode(data),
92
- json: () => JSON.parse(new TextDecoder('utf-8').decode(data)),
93
- hex: () => bytesToHex(data),
94
- });
95
- }
96
+ return Object.assign(data, {
97
+ text: () => new TextDecoder('utf-8').decode(data),
98
+ json: () => JSON.parse(new TextDecoder('utf-8').decode(data)),
99
+ hex: () => bytesToHex(data)
100
+ });
101
+ }
@@ -5,7 +5,7 @@
5
5
  * @param dir path to the directory
6
6
  */
7
7
  export async function makeCollectionFromFS(dir) {
8
- throw new Error('Creating Collection from File System is not supported in browsers!');
8
+ throw new Error('Creating Collection from File System is not supported in browsers!');
9
9
  }
10
10
  /**
11
11
  * Calculate folder size recursively
@@ -13,6 +13,7 @@ export async function makeCollectionFromFS(dir) {
13
13
  * @param dir the path to the folder to check
14
14
  * @returns size in bytes
15
15
  */
16
+
16
17
  export async function getFolderSize(dir) {
17
- throw new Error('Creating Collection from File System is not supported in browsers!');
18
- }
18
+ throw new Error('Creating Collection from File System is not supported in browsers!');
19
+ }
@@ -1,38 +1,46 @@
1
- import { BeeArgumentError } from './error';
2
- import { fileArrayBuffer } from './file';
3
- import { isUint8Array } from './type';
1
+ import { BeeArgumentError } from "./error.js";
2
+ import { fileArrayBuffer } from "./file.js";
3
+ import { isUint8Array } from "./type.js";
4
4
  export function isCollection(data) {
5
- if (!Array.isArray(data)) {
6
- return false;
7
- }
8
- return data.every(entry => typeof entry === 'object' && entry.data && entry.path && isUint8Array(entry.data));
5
+ if (!Array.isArray(data)) {
6
+ return false;
7
+ }
8
+
9
+ return data.every(entry => typeof entry === 'object' && entry.data && entry.path && isUint8Array(entry.data));
9
10
  }
10
11
  export function assertCollection(data) {
11
- if (!isCollection(data)) {
12
- throw new BeeArgumentError('invalid collection', data);
13
- }
12
+ if (!isCollection(data)) {
13
+ throw new BeeArgumentError('invalid collection', data);
14
+ }
14
15
  }
16
+
15
17
  function makeFilePath(file) {
16
- if (file.webkitRelativePath && file.webkitRelativePath !== '') {
17
- return file.webkitRelativePath.replace(/.*?\//i, '');
18
- }
19
- if (file.name) {
20
- return file.name;
21
- }
22
- throw new TypeError('file is not valid File object');
18
+ if (file.webkitRelativePath && file.webkitRelativePath !== '') {
19
+ return file.webkitRelativePath.replace(/.*?\//i, '');
20
+ }
21
+
22
+ if (file.name) {
23
+ return file.name;
24
+ }
25
+
26
+ throw new TypeError('file is not valid File object');
23
27
  }
28
+
24
29
  export async function makeCollectionFromFileList(fileList) {
25
- const collection = [];
26
- for (let i = 0; i < fileList.length; i++) {
27
- const file = fileList[i];
28
- if (file) {
29
- collection.push({
30
- path: makeFilePath(file),
31
- data: new Uint8Array(await fileArrayBuffer(file)),
32
- });
33
- }
30
+ const collection = [];
31
+
32
+ for (let i = 0; i < fileList.length; i++) {
33
+ const file = fileList[i];
34
+
35
+ if (file) {
36
+ collection.push({
37
+ path: makeFilePath(file),
38
+ data: new Uint8Array(await fileArrayBuffer(file))
39
+ });
34
40
  }
35
- return collection;
41
+ }
42
+
43
+ return collection;
36
44
  }
37
45
  /**
38
46
  * Calculate cumulative size of files
@@ -40,13 +48,17 @@ export async function makeCollectionFromFileList(fileList) {
40
48
  * @param fileList list of files to check
41
49
  * @returns size in bytes
42
50
  */
51
+
43
52
  export function getCollectionSize(fileList) {
44
- let sum = 0;
45
- for (let i = 0; i < fileList.length; i++) {
46
- const file = fileList[i];
47
- if (file) {
48
- sum += file.size;
49
- }
53
+ let sum = 0;
54
+
55
+ for (let i = 0; i < fileList.length; i++) {
56
+ const file = fileList[i];
57
+
58
+ if (file) {
59
+ sum += file.size;
50
60
  }
51
- return sum;
52
- }
61
+ }
62
+
63
+ return sum;
64
+ }
@@ -6,34 +6,40 @@ import path from 'path';
6
6
  *
7
7
  * @param dir path to the directory
8
8
  */
9
+
9
10
  export async function makeCollectionFromFS(dir) {
10
- if (typeof dir !== 'string') {
11
- throw new TypeError('dir has to be string!');
12
- }
13
- if (dir === '') {
14
- throw new TypeError('dir must not be empty string!');
15
- }
16
- return buildCollectionRelative(dir, '');
11
+ if (typeof dir !== 'string') {
12
+ throw new TypeError('dir has to be string!');
13
+ }
14
+
15
+ if (dir === '') {
16
+ throw new TypeError('dir must not be empty string!');
17
+ }
18
+
19
+ return buildCollectionRelative(dir, '');
17
20
  }
21
+
18
22
  async function buildCollectionRelative(dir, relativePath) {
19
- // Handles case when the dir is not existing or it is a file ==> throws an error
20
- const dirname = path.join(dir, relativePath);
21
- const entries = await fs.promises.opendir(dirname);
22
- let collection = [];
23
- for await (const entry of entries) {
24
- const fullPath = path.join(dir, relativePath, entry.name);
25
- const entryPath = path.join(relativePath, entry.name);
26
- if (entry.isFile()) {
27
- collection.push({
28
- path: entryPath,
29
- data: new Uint8Array(await fs.promises.readFile(fullPath)),
30
- });
31
- }
32
- else if (entry.isDirectory()) {
33
- collection = [...(await buildCollectionRelative(dir, entryPath)), ...collection];
34
- }
23
+ // Handles case when the dir is not existing or it is a file ==> throws an error
24
+ const dirname = path.join(dir, relativePath);
25
+ const entries = await fs.promises.opendir(dirname);
26
+ let collection = [];
27
+
28
+ for await (const entry of entries) {
29
+ const fullPath = path.join(dir, relativePath, entry.name);
30
+ const entryPath = path.join(relativePath, entry.name);
31
+
32
+ if (entry.isFile()) {
33
+ collection.push({
34
+ path: entryPath,
35
+ data: new Uint8Array(await fs.promises.readFile(fullPath))
36
+ });
37
+ } else if (entry.isDirectory()) {
38
+ collection = [...(await buildCollectionRelative(dir, entryPath)), ...collection];
35
39
  }
36
- return collection;
40
+ }
41
+
42
+ return collection;
37
43
  }
38
44
  /**
39
45
  * Calculate folder size recursively
@@ -41,23 +47,28 @@ async function buildCollectionRelative(dir, relativePath) {
41
47
  * @param dir the path to the folder to check
42
48
  * @returns size in bytes
43
49
  */
50
+
51
+
44
52
  export async function getFolderSize(dir) {
45
- if (typeof dir !== 'string') {
46
- throw new TypeError('dir has to be string!');
47
- }
48
- if (dir === '') {
49
- throw new TypeError('dir must not be empty string!');
53
+ if (typeof dir !== 'string') {
54
+ throw new TypeError('dir has to be string!');
55
+ }
56
+
57
+ if (dir === '') {
58
+ throw new TypeError('dir must not be empty string!');
59
+ }
60
+
61
+ const entries = await fs.promises.opendir(dir);
62
+ let size = 0;
63
+
64
+ for await (const entry of entries) {
65
+ if (entry.isFile()) {
66
+ const stats = await fs.promises.stat(path.join(dir, entry.name));
67
+ size += stats.size;
68
+ } else if (entry.isDirectory()) {
69
+ size += await getFolderSize(path.join(dir, entry.name));
50
70
  }
51
- const entries = await fs.promises.opendir(dir);
52
- let size = 0;
53
- for await (const entry of entries) {
54
- if (entry.isFile()) {
55
- const stats = await fs.promises.stat(path.join(dir, entry.name));
56
- size += stats.size;
57
- }
58
- else if (entry.isDirectory()) {
59
- size += await getFolderSize(path.join(dir, entry.name));
60
- }
61
- }
62
- return size;
63
- }
71
+ }
72
+
73
+ return size;
74
+ }