@ezs/basics 2.1.3 → 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 +11 -0
- package/README.md +22 -0
- package/lib/index.js +3 -0
- package/lib/tar-extract.js +90 -0
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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
|
+
|
|
6
17
|
## [2.1.3](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@2.1.2...@ezs/basics@2.1.3) (2023-05-30)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @ezs/basics
|
package/README.md
CHANGED
|
@@ -27,6 +27,7 @@ npm install @ezs/basics
|
|
|
27
27
|
- [OBJFlatten](#objflatten)
|
|
28
28
|
- [OBJNamespaces](#objnamespaces)
|
|
29
29
|
- [OBJStandardize](#objstandardize)
|
|
30
|
+
- [TARExtract](#tarextract)
|
|
30
31
|
- [TXTConcat](#txtconcat)
|
|
31
32
|
- [TXTInflection](#txtinflection)
|
|
32
33
|
- [TXTObject](#txtobject)
|
|
@@ -536,6 +537,27 @@ Output:
|
|
|
536
537
|
|
|
537
538
|
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
|
538
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)<{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
|
+
|
|
539
561
|
### TXTConcat
|
|
540
562
|
|
|
541
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
|
+
}
|
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.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": "
|
|
44
|
+
"gitHead": "6868634896b6171224fe54c59360a3668d71bd5f",
|
|
44
45
|
"homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
|
|
45
46
|
"keywords": [
|
|
46
47
|
"ezs"
|