You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### `getFolderSize.loose(path, [options]): number | bigint`
49
49
The `loose` method will return the folder size directly and ignore any errors it encounters, which means the returned folder size could be smaller than the real folder size.
50
50
51
51
This method is great if the precise size isn't too important, for example when used only to display the folder size to the user.
### `getFolderSize.strict(path, [options]): number | bigint`
54
54
The `strict` method will return the folder size directly, but throw an error if it encounters any read errors.
55
55
56
56
This method is great if you need a very accurate number. You will have to implement some sort of error handling to use it reliably.
@@ -63,12 +63,15 @@ Any of the three methods can also take an `options` object:
63
63
getFolderSize(
64
64
'/path/to/folder',
65
65
{
66
+
bigint:true,
66
67
ignore:/pattern/,
67
68
fs: customFS,
68
69
}
69
70
)
70
71
```
71
72
73
+
If the `bigint` option is set to true, the folder size is returned as a BigInt instead of the default Number.
74
+
72
75
The `ignore` option takes a regex pattern. Any file or folder with a path that matches the pattern will not be counted in the total folder size.
73
76
74
77
The `fs` option allows you to pass a different filesystem handler, such as [memfs](https://github.com/streamich/memfs), that will be used to read the folder size. The filesystem handler must incorporate `lstat` and `readdir` promise functions.
Copy file name to clipboardExpand all lines: index.js
+32-17Lines changed: 32 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -6,12 +6,13 @@ import { join as joinPaths } from 'path';
6
6
*
7
7
* If any errors are returned, the returned folder size is likely smaller than the real folder size.
8
8
*
9
-
* @param {string} itemPath - Path of the folder.
10
-
* @param {object} [options] - Options.
11
-
* @param {object} [options.ignore] - If a file's path matches this regex object, its size is not counted.
12
-
* @param {object} [options.fs] - The filesystem that should be used. Uses node fs by default.
9
+
* @param {string} itemPath - Path of the folder.
10
+
* @param {object} [options] - Options.
11
+
* @param {boolean} [options.bigint] - Should the folder size be returned as a BigInt instead of a Number.
12
+
* @param {object} [options.ignore] - If a file's path matches this regex object, its size is not counted.
13
+
* @param {object} [options.fs] - The filesystem that should be used. Uses node fs by default.
13
14
*
14
-
* @returns {Promise<{size: number, errors: Array<Error> | null}>} - An object containing the size of the folder in bytes and a list of encountered errors.
15
+
* @returns {Promise<{size: number | bigint, errors: Array<Error> | null}>} - An object containing the size of the folder in bytes and a list of encountered errors.
tap.type(errors,Array,'should return Array of errors');
164
+
tap.equal(errors.length,1,'should return one error');
165
+
tap.equal(errors[0].message,'The folder size is too large to return as a Number. You can instruct this package to return a BigInt instead.','should return appropriate error');
166
+
167
+
tap.end();
168
+
169
+
});
170
+
171
+
tap.test('returning BigInt',async()=>{
172
+
173
+
tap.equal(awaitgetFolderSize.loose('/fixture',{bigint: true,fs: largeFS}),BigInt(Number.MAX_SAFE_INTEGER)*4n,'should return size of 4 times max safe Number');
174
+
175
+
tap.equal(awaitgetFolderSize.strict('/fixture',{bigint: true,fs: largeFS}),BigInt(Number.MAX_SAFE_INTEGER)*4n,'should return size of 4 times max safe Number');
0 commit comments