@ezs/basics 2.6.1 → 2.7.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 +33 -0
- package/lib/file-merge.js +57 -0
- package/lib/index.js +2 -0
- package/lib/tar-extract.js +15 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ npm install @ezs/basics
|
|
|
20
20
|
- [CSVParse](#csvparse)
|
|
21
21
|
- [CSVString](#csvstring)
|
|
22
22
|
- [FILELoad](#fileload)
|
|
23
|
+
- [FILEMerge](#filemerge)
|
|
23
24
|
- [FILESave](#filesave)
|
|
24
25
|
- [INIString](#inistring)
|
|
25
26
|
- [JSONParse](#jsonparse)
|
|
@@ -251,6 +252,37 @@ Output:
|
|
|
251
252
|
|
|
252
253
|
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
|
253
254
|
|
|
255
|
+
### FILEMerge
|
|
256
|
+
|
|
257
|
+
Take `Object` or `Buffer` and throw only one document
|
|
258
|
+
|
|
259
|
+
```json
|
|
260
|
+
[ fi1e1.csv, file2.csv ]
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Script:
|
|
264
|
+
|
|
265
|
+
```ini
|
|
266
|
+
[use]
|
|
267
|
+
plugin = basics
|
|
268
|
+
|
|
269
|
+
[FILELoad]
|
|
270
|
+
[FILEMerge]
|
|
271
|
+
[replace]
|
|
272
|
+
path = contentOfFile1AndFile2
|
|
273
|
+
value = self()
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Output:
|
|
277
|
+
|
|
278
|
+
```json
|
|
279
|
+
[
|
|
280
|
+
(...)
|
|
281
|
+
]
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
|
285
|
+
|
|
254
286
|
### FILESave
|
|
255
287
|
|
|
256
288
|
Take data, convert it to buffer and append it to file
|
|
@@ -591,6 +623,7 @@ It returns to the output stream
|
|
|
591
623
|
|
|
592
624
|
- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Regex to select the files to extract (optional, default `"**\/*.json"`)
|
|
593
625
|
- `json` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Parse as JSON the content of each file (optional, default `true`)
|
|
626
|
+
- `text` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** The content of each file is converted to a string (otherwise it remains a buffer) (optional, default `true`)
|
|
594
627
|
- `compress` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Enable gzip compression (optional, default `false`)
|
|
595
628
|
|
|
596
629
|
Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<{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)}>**
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = FILEMerge;
|
|
7
|
+
/**
|
|
8
|
+
* Take `Object` or `Buffer` and throw only one document
|
|
9
|
+
*
|
|
10
|
+
* ```json
|
|
11
|
+
* [ fi1e1.csv, file2.csv ]
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Script:
|
|
15
|
+
*
|
|
16
|
+
* ```ini
|
|
17
|
+
* [use]
|
|
18
|
+
* plugin = basics
|
|
19
|
+
*
|
|
20
|
+
* [FILELoad]
|
|
21
|
+
* [FILEMerge]
|
|
22
|
+
* [replace]
|
|
23
|
+
* path = contentOfFile1AndFile2
|
|
24
|
+
* value = self()
|
|
25
|
+
*
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Output:
|
|
29
|
+
*
|
|
30
|
+
* ```json
|
|
31
|
+
* [
|
|
32
|
+
* (...)
|
|
33
|
+
* ]
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @name FILEMerge
|
|
37
|
+
* @returns {Object}
|
|
38
|
+
*/
|
|
39
|
+
function FILEMerge(data, feed) {
|
|
40
|
+
if (this.isFirst()) {
|
|
41
|
+
this.chunks = [];
|
|
42
|
+
this.length = 0;
|
|
43
|
+
this.isBuffer = Buffer.isBuffer(data);
|
|
44
|
+
}
|
|
45
|
+
if (this.isLast()) {
|
|
46
|
+
feed.write(this.isBuffer ? Buffer.concat(this.chunks, this.length) : this.chunks.join(''));
|
|
47
|
+
feed.close();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (this.isBuffer) {
|
|
51
|
+
this.length += data.length;
|
|
52
|
+
} else {
|
|
53
|
+
this.length = this.chunks.length;
|
|
54
|
+
}
|
|
55
|
+
this.chunks.push(data);
|
|
56
|
+
feed.end();
|
|
57
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -37,6 +37,7 @@ var _tarDump = _interopRequireDefault(require("./tar-dump"));
|
|
|
37
37
|
var _iniString = _interopRequireDefault(require("./ini-string"));
|
|
38
38
|
var _fileSave = _interopRequireDefault(require("./file-save"));
|
|
39
39
|
var _fileLoad = _interopRequireDefault(require("./file-load"));
|
|
40
|
+
var _fileMerge = _interopRequireDefault(require("./file-merge"));
|
|
40
41
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
41
42
|
const funcs = {
|
|
42
43
|
BUFObject: _bufObject.default,
|
|
@@ -72,6 +73,7 @@ const funcs = {
|
|
|
72
73
|
INIString: _iniString.default,
|
|
73
74
|
FILESave: _fileSave.default,
|
|
74
75
|
FILELoad: _fileLoad.default,
|
|
76
|
+
FILEMerge: _fileMerge.default,
|
|
75
77
|
// aliases
|
|
76
78
|
bufferify: _bufObject.default.BUFObject,
|
|
77
79
|
concat: _txtConcat.default.TXTConcat,
|
package/lib/tar-extract.js
CHANGED
|
@@ -25,6 +25,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
25
25
|
* @name TARExtract
|
|
26
26
|
* @param {String} [path="**\/*.json"] Regex to select the files to extract
|
|
27
27
|
* @param {String} [json=true] Parse as JSON the content of each file
|
|
28
|
+
* @param {Boolean} [text=true] The content of each file is converted to a string (otherwise it remains a buffer)
|
|
28
29
|
* @param {Boolean} [compress=false] Enable gzip compression
|
|
29
30
|
* @returns {{id: String, value: String}[]}
|
|
30
31
|
*/
|
|
@@ -34,7 +35,8 @@ function TARExtract(data, feed) {
|
|
|
34
35
|
const {
|
|
35
36
|
ezs
|
|
36
37
|
} = this;
|
|
37
|
-
const
|
|
38
|
+
const text = this.getParam('text', true);
|
|
39
|
+
const json = text ? this.getParam('json', true) : false;
|
|
38
40
|
const compress = this.getParam('compress', false);
|
|
39
41
|
this.input = ezs.createStream(ezs.objectMode());
|
|
40
42
|
this.output = ezs.createStream(ezs.objectMode());
|
|
@@ -43,11 +45,21 @@ function TARExtract(data, feed) {
|
|
|
43
45
|
extract.on('entry', async (header, stream, next) => {
|
|
44
46
|
if (_micromatch.default.isMatch(header.name, filesPatern)) {
|
|
45
47
|
try {
|
|
46
|
-
const contentRaw = await (0, _getStream.default)(stream);
|
|
47
48
|
if (json) {
|
|
48
|
-
const
|
|
49
|
+
const contentText = await (0, _getStream.default)(stream);
|
|
50
|
+
const contentJson = JSON.parse(contentText);
|
|
49
51
|
return (0, _streamWrite.default)(this.output, contentJson, () => next());
|
|
50
52
|
}
|
|
53
|
+
if (text) {
|
|
54
|
+
const contentText = await (0, _getStream.default)(stream);
|
|
55
|
+
return (0, _streamWrite.default)(this.output, {
|
|
56
|
+
id: header.name,
|
|
57
|
+
value: contentText
|
|
58
|
+
}, () => next());
|
|
59
|
+
}
|
|
60
|
+
const contentRaw = await (0, _getStream.default)(stream, {
|
|
61
|
+
encoding: 'buffer'
|
|
62
|
+
});
|
|
51
63
|
return (0, _streamWrite.default)(this.output, {
|
|
52
64
|
id: header.name,
|
|
53
65
|
value: contentRaw
|
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.
|
|
4
|
+
"version": "2.7.0",
|
|
5
5
|
"author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
|
|
6
6
|
"bugs": "https://github.com/Inist-CNRS/ezs/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"directories": {
|
|
37
37
|
"test": "test"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "0cbe93a845e6d4fe89501d3d7b4d2bd0f77f0297",
|
|
40
40
|
"homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
|
|
41
41
|
"keywords": [
|
|
42
42
|
"ezs"
|