@ezs/basics 2.1.1 → 2.2.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/CHANGELOG.md CHANGED
@@ -3,6 +3,36 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [2.2.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@2.1.3...@ezs/basics@2.2.0) (2023-06-22)
7
+
8
+
9
+ ### Features
10
+
11
+ * 🎸 add tar-extract ([a471aca](https://github.com/Inist-CNRS/ezs/commit/a471aca64b7ab08d92237917264a23080a2c3072))
12
+
13
+
14
+
15
+
16
+
17
+ ## [2.1.3](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@2.1.2...@ezs/basics@2.1.3) (2023-05-30)
18
+
19
+ **Note:** Version bump only for package @ezs/basics
20
+
21
+
22
+
23
+
24
+
25
+ ## [2.1.2](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@2.1.1...@ezs/basics@2.1.2) (2023-05-30)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * 🐛 retry without json parse ([90e17b5](https://github.com/Inist-CNRS/ezs/commit/90e17b5ea2cbf60f18a9ecbf29b338b1395e318e))
31
+
32
+
33
+
34
+
35
+
6
36
  ## [2.1.1](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@2.1.0...@ezs/basics@2.1.1) (2023-05-12)
7
37
 
8
38
  **Note:** Version bump only for package @ezs/basics
package/README.md CHANGED
@@ -23,11 +23,11 @@ npm install @ezs/basics
23
23
  - [INIString](#inistring)
24
24
  - [JSONParse](#jsonparse)
25
25
  - [JSONString](#jsonstring)
26
- - [OBJColumns](#objcolumns)
27
26
  - [OBJCount](#objcount)
28
27
  - [OBJFlatten](#objflatten)
29
28
  - [OBJNamespaces](#objnamespaces)
30
29
  - [OBJStandardize](#objstandardize)
30
+ - [TARExtract](#tarextract)
31
31
  - [TXTConcat](#txtconcat)
32
32
  - [TXTInflection](#txtinflection)
33
33
  - [TXTObject](#txtobject)
@@ -393,38 +393,6 @@ Output:
393
393
 
394
394
  Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
395
395
 
396
- ### OBJColumns
397
-
398
- Take an `Object` and flatten it to get only one level of keys.
399
-
400
- <caption>Input:</caption>
401
-
402
- ```json
403
- [{
404
- "foo": {
405
- "hello": "world"
406
- },
407
- "bar": "anything else",
408
- "baz": 1
409
- }]
410
- ```
411
-
412
- <caption>Output:</caption>
413
-
414
- ```json
415
- [{
416
- "foo": "{\"hello\":\"world\"}",
417
- "bar": "anything else",
418
- "baz": 1
419
- }]
420
- ```
421
-
422
- #### Parameters
423
-
424
- - `none` **[undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)**
425
-
426
- Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
427
-
428
396
  ### OBJCount
429
397
 
430
398
  Count how many objects are received, and yield the total.
@@ -569,6 +537,27 @@ Output:
569
537
 
570
538
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
571
539
 
540
+ ### TARExtract
541
+
542
+ Take the content of a tar file, extract some files.
543
+ The JSON object is sent to the output stream for each file.
544
+ It returns to the output stream
545
+
546
+ ```json
547
+ {
548
+ "id": "file name",
549
+ "value": "file contents"
550
+ }
551
+ ```
552
+
553
+ #### Parameters
554
+
555
+ - `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Regex to select the files to extract (optional, default `"**\/*.json"`)
556
+ - `json` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Parse as JSON the content of each file (optional, default `true`)
557
+ - `compress` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Enable gzip compression (optional, default `false`)
558
+
559
+ Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;{id: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), value: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>**
560
+
572
561
  ### TXTConcat
573
562
 
574
563
  Concatenate all `String` items into one string
package/lib/index.js CHANGED
@@ -59,6 +59,8 @@ var _txtZip = _interopRequireDefault(require("./txt-zip"));
59
59
 
60
60
  var _zipExtract = _interopRequireDefault(require("./zip-extract"));
61
61
 
62
+ var _tarExtract = _interopRequireDefault(require("./tar-extract"));
63
+
62
64
  var _iniString = _interopRequireDefault(require("./ini-string"));
63
65
 
64
66
  var _fileSave = _interopRequireDefault(require("./file-save"));
@@ -95,6 +97,7 @@ const funcs = {
95
97
  URLConnect: _urlConnect.default,
96
98
  TXTZip: _txtZip.default,
97
99
  ZIPExtract: _zipExtract.default,
100
+ TARExtract: _tarExtract.default,
98
101
  INIString: _iniString.default,
99
102
  FILESave: _fileSave.default,
100
103
  FILELoad: _fileLoad.default,
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = TARExtract;
7
+
8
+ var _tarStream = _interopRequireDefault(require("tar-stream"));
9
+
10
+ var _micromatch = _interopRequireDefault(require("micromatch"));
11
+
12
+ var _zlib = require("zlib");
13
+
14
+ var _getStream = _interopRequireDefault(require("get-stream"));
15
+
16
+ var _streamWrite = _interopRequireDefault(require("stream-write"));
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ /**
21
+ * Take the content of a tar file, extract some files.
22
+ * The JSON object is sent to the output stream for each file.
23
+ * It returns to the output stream
24
+ *
25
+ * ```json
26
+ * {
27
+ * "id": "file name",
28
+ * "value": "file contents"
29
+ * }
30
+ * ```
31
+ *
32
+ * @name TARExtract
33
+ * @param {String} [path="**\/*.json"] Regex to select the files to extract
34
+ * @param {String} [json=true] Parse as JSON the content of each file
35
+ * @param {Boolean} [compress=false] Enable gzip compression
36
+ * @returns {{id: String, value: String}[]}
37
+ */
38
+ function TARExtract(data, feed) {
39
+ const filesPatern = this.getParam('path', '**/*.json');
40
+
41
+ if (this.isFirst()) {
42
+ const {
43
+ ezs
44
+ } = this;
45
+ const json = this.getParam('json', true);
46
+ const compress = this.getParam('compress', false);
47
+ this.input = ezs.createStream(ezs.objectMode());
48
+ this.output = ezs.createStream(ezs.objectMode());
49
+
50
+ const extract = _tarStream.default.extract();
51
+
52
+ this.whenEnd = new Promise((resolve, reject) => {
53
+ extract.on('entry', async (header, stream, next) => {
54
+ if (_micromatch.default.isMatch(header.name, filesPatern)) {
55
+ const contentRaw = await (0, _getStream.default)(stream);
56
+
57
+ if (json) {
58
+ const contentJson = JSON.parse(contentRaw);
59
+ return (0, _streamWrite.default)(this.output, contentJson, () => next());
60
+ }
61
+
62
+ return (0, _streamWrite.default)(this.output, {
63
+ id: header.name,
64
+ value: contentRaw
65
+ }, () => next());
66
+ }
67
+
68
+ return next();
69
+ });
70
+ extract.on('error', reject);
71
+ extract.on('finish', resolve);
72
+ });
73
+
74
+ if (compress) {
75
+ this.input.pipe((0, _zlib.createGunzip)()).pipe(extract);
76
+ } else {
77
+ this.input.pipe(extract);
78
+ }
79
+
80
+ this.whenFinish = feed.flow(this.output);
81
+ }
82
+
83
+ if (this.isLast()) {
84
+ this.whenEnd.finally(() => this.output.end());
85
+ this.whenFinish.finally(() => feed.close());
86
+ this.input.end();
87
+ } else {
88
+ (0, _streamWrite.default)(this.input, data, () => feed.end());
89
+ }
90
+ }
@@ -106,9 +106,13 @@ async function URLConnect(data, feed) {
106
106
  });
107
107
  bodyOut.pipe(output);
108
108
  } else {
109
- const bodyOutRaw = await (0, _getStream.default)(response.body);
110
- const bodyOutArray = JSON.parse(bodyOutRaw);
111
- (0, _from.default)(bodyOutArray).pipe(output);
109
+ if (json) {
110
+ const bodyOutRaw = await (0, _getStream.default)(response.body);
111
+ const bodyOutArray = JSON.parse(bodyOutRaw);
112
+ (0, _from.default)(bodyOutArray).pipe(output);
113
+ } else {
114
+ response.body.pipe(output);
115
+ }
112
116
  }
113
117
  }, {
114
118
  retries
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ezs/basics",
3
3
  "description": "Basics statements for EZS",
4
- "version": "2.1.1",
4
+ "version": "2.2.0",
5
5
  "author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
6
6
  "bugs": "https://github.com/Inist-CNRS/ezs/issues",
7
7
  "dependencies": {
@@ -28,6 +28,7 @@
28
28
  "parse-headers": "2.0.4",
29
29
  "path-exists": "4.0.0",
30
30
  "stream-write": "1.0.1",
31
+ "tar-stream": "3.1.4",
31
32
  "tmp-filepath": "2.0.0",
32
33
  "unzipper": "0.10.11",
33
34
  "xml-mapping": "1.7.2",
@@ -40,7 +41,7 @@
40
41
  "directories": {
41
42
  "test": "test"
42
43
  },
43
- "gitHead": "54e12b40d2cd6ccb6754f06ab5cae566c60bb3a9",
44
+ "gitHead": "6868634896b6171224fe54c59360a3668d71bd5f",
44
45
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
45
46
  "keywords": [
46
47
  "ezs"