@vbarbarosh/node-helpers 3.8.0 → 3.10.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/README.md CHANGED
@@ -7,3 +7,16 @@ A set of helpers for JavaScript/Node.js
7
7
  ## Test
8
8
 
9
9
  bin/test
10
+
11
+ ## Conventions
12
+
13
+ `concurrency` - limit for parallel processes.
14
+
15
+ * [Node • Stream • readable.every](https://nodejs.org/api/stream.html#readableeveryfn-options)
16
+ * [Node • Stream • readable.filter](https://nodejs.org/api/stream.html#readablefilterfn-options)
17
+ * [Node • Stream • readable.find](https://nodejs.org/api/stream.html#readablefindfn-options)
18
+ * [Node • Stream • readable.flatMap](https://nodejs.org/api/stream.html#readableflatmapfn-options)
19
+ * [Node • Stream • readable.forEach](https://nodejs.org/api/stream.html#readableforeachfn-options)
20
+ * [Node • Stream • readable.map](https://nodejs.org/api/stream.html#readablemapfn-options)
21
+ * [Node • Stream • readable.some](https://nodejs.org/api/stream.html#readablesomefn-options)
22
+ * [bluebird • Promise.map](http://bluebirdjs.com/docs/api/promise.map.html)
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
3
3
  "license": "MIT",
4
4
  "name": "@vbarbarosh/node-helpers",
5
- "version": "3.8.0",
5
+ "version": "3.10.0",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "files": [
8
8
  "src"
@@ -0,0 +1,24 @@
1
+ // https://github.com/nodejs/node/issues/36084#issuecomment-729894622
2
+ class AbortError extends Error
3
+ {
4
+ constructor(message = 'The operation was aborted') {
5
+ super(message);
6
+ this.name = 'AbortError';
7
+ this.code = 'ABORT_ERR';
8
+ }
9
+
10
+ static absorb(error) {
11
+ if (AbortError.check(error)) {
12
+ return;
13
+ }
14
+ throw error;
15
+ }
16
+
17
+ static check(error) {
18
+ return error
19
+ && (error.name === 'AbortError')
20
+ && (error.code === 'ABORT_ERR');
21
+ }
22
+ }
23
+
24
+ module.exports = AbortError;
@@ -0,0 +1,12 @@
1
+ const crypto = require('crypto');
2
+ const fs = require('fs');
3
+
4
+ async function fs_file_md5(file, encoding = 'hex')
5
+ {
6
+ const md5 = crypto.createHash('md5');
7
+ const rs = fs.createReadStream(file);
8
+ await rs.forEach(v => md5.update(v));
9
+ return md5.digest(encoding);
10
+ }
11
+
12
+ module.export = fs_file_md5;