@ezs/basics 1.22.7 → 1.23.1
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 +28 -0
- package/README.md +2 -0
- package/lib/file-load.js +12 -7
- package/lib/file-save.js +20 -3
- package/lib/obj-standardize.js +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,34 @@
|
|
|
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
|
+
## [1.23.1](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.23.0...@ezs/basics@1.23.1) (2023-01-28)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* 🐛 improve security in file access ([6942a8e](https://github.com/Inist-CNRS/ezs/commit/6942a8e039a05d820d8643fa0908287a0a6aefda))
|
|
12
|
+
* 🐛 objstandarize lost boolean values ([dca4714](https://github.com/Inist-CNRS/ezs/commit/dca4714c984214f422f9ed8951575de66af0f0ce))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Reverts
|
|
16
|
+
|
|
17
|
+
* Revert "chore: 🤖 use lerna exec instead bootstrap" ([56375ee](https://github.com/Inist-CNRS/ezs/commit/56375ee2bd7e9f69f61da3993ab569ca1c16c547))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# [1.23.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.22.7...@ezs/basics@1.23.0) (2023-01-20)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Features
|
|
27
|
+
|
|
28
|
+
* 🎸 add new parameter to FILESave ([8fae7b8](https://github.com/Inist-CNRS/ezs/commit/8fae7b8009824d8e73c98e8277e15ffacd87d572))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
6
34
|
## [1.22.7](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.22.6...@ezs/basics@1.22.7) (2023-01-13)
|
|
7
35
|
|
|
8
36
|
|
package/README.md
CHANGED
|
@@ -262,6 +262,8 @@ Output:
|
|
|
262
262
|
|
|
263
263
|
- `location` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Directory location (optional, default `TMPDIR`)
|
|
264
264
|
- `identifier` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** File name
|
|
265
|
+
- `content` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Content to save instead of using input object
|
|
266
|
+
- `jsonl` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Save as json line (optional, default `false`)
|
|
265
267
|
- `compress` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Enable gzip compression (optional, default `false`)
|
|
266
268
|
|
|
267
269
|
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
package/lib/file-load.js
CHANGED
|
@@ -13,6 +13,10 @@ var _path = require("path");
|
|
|
13
13
|
|
|
14
14
|
var _os = require("os");
|
|
15
15
|
|
|
16
|
+
var _higherPath = _interopRequireDefault(require("higher-path"));
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
16
20
|
/**
|
|
17
21
|
* Take `Object` containing filename et throw content by chunk
|
|
18
22
|
*
|
|
@@ -52,18 +56,19 @@ async function FILELoad(data, feed) {
|
|
|
52
56
|
return;
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
const cwd = process.cwd();
|
|
56
|
-
const tpd = (0, _os.tmpdir)();
|
|
57
59
|
const compress = this.getParam('compress', false);
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
+
const location = (0, _path.normalize)(this.getParam('location', '/'));
|
|
61
|
+
const locations = [(0, _higherPath.default)((0, _os.tmpdir)(), location), (0, _higherPath.default)(process.cwd(), location)];
|
|
62
|
+
const filename = locations.filter(Boolean).map(dir => (0, _path.resolve)(dir, String(data).trim())).filter(fil => (0, _fs.existsSync)(fil)).shift();
|
|
60
63
|
|
|
61
|
-
if (!
|
|
62
|
-
feed.
|
|
64
|
+
if (!filename) {
|
|
65
|
+
feed.stop(new Error('File location check failed.'));
|
|
63
66
|
return;
|
|
64
67
|
}
|
|
65
68
|
|
|
66
|
-
|
|
69
|
+
(0, _fs.accessSync)((0, _path.dirname)(filename), _fs.constants.R_OK | _fs.constants.W_OK);
|
|
70
|
+
(0, _fs.accessSync)(filename, _fs.constants.R_OK | _fs.constants.W_OK);
|
|
71
|
+
const stream = compress ? (0, _fs.createReadStream)(filename).pipe((0, _zlib.createGunzip)()) : (0, _fs.createReadStream)(filename);
|
|
67
72
|
await feed.flow(stream);
|
|
68
73
|
return;
|
|
69
74
|
}
|
package/lib/file-save.js
CHANGED
|
@@ -23,6 +23,9 @@ var _debug = _interopRequireDefault(require("debug"));
|
|
|
23
23
|
|
|
24
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
25
|
|
|
26
|
+
const eol = '\n';
|
|
27
|
+
|
|
28
|
+
const toJSONL = line => JSON.stringify(line).concat(eol);
|
|
26
29
|
/**
|
|
27
30
|
* Take data, convert it to buffer and append it to file
|
|
28
31
|
*
|
|
@@ -55,21 +58,31 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
55
58
|
* @name FILESave
|
|
56
59
|
* @param {String} [location=TMPDIR] Directory location
|
|
57
60
|
* @param {String} [identifier] File name
|
|
61
|
+
* @param {String} [content] Content to save instead of using input object
|
|
62
|
+
* @param {Boolean} [jsonl=false] Save as json line
|
|
58
63
|
* @param {Boolean} [compress=false] Enable gzip compression
|
|
59
64
|
* @returns {Object}
|
|
60
65
|
*/
|
|
61
|
-
function FILESave(data, feed) {
|
|
62
|
-
const buf = Buffer.from(String(data));
|
|
63
66
|
|
|
67
|
+
|
|
68
|
+
function FILESave(data, feed) {
|
|
64
69
|
if (this.isFirst()) {
|
|
65
70
|
const identifier = String(this.getParam('identifier'));
|
|
66
|
-
|
|
71
|
+
|
|
72
|
+
const location = _path.default.normalize(this.getParam('location', (0, _os.tmpdir)()));
|
|
73
|
+
|
|
67
74
|
const compress = this.getParam('compress', false);
|
|
68
75
|
|
|
76
|
+
if (location.indexOf((0, _os.tmpdir)()) !== 0 && location.indexOf(process.cwd()) !== 0) {
|
|
77
|
+
feed.stop(new Error('File location check failed.'));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
69
81
|
if (!_pathExists.default.sync(location)) {
|
|
70
82
|
_makeDir.default.sync(location);
|
|
71
83
|
}
|
|
72
84
|
|
|
85
|
+
(0, _fs.accessSync)(location, _fs.constants.R_OK | _fs.constants.W_OK);
|
|
73
86
|
const name = compress ? `${identifier}.gz` : identifier;
|
|
74
87
|
|
|
75
88
|
const filename = _path.default.resolve(location, name);
|
|
@@ -102,5 +115,9 @@ function FILESave(data, feed) {
|
|
|
102
115
|
return this.whenFinish.then(stats => feed.write(stats)).catch(err => feed.stop(err)).finally(() => feed.close());
|
|
103
116
|
}
|
|
104
117
|
|
|
118
|
+
const jsonl = Boolean(this.getParam('jsonl', false));
|
|
119
|
+
const bufContent = this.getParam('content', data);
|
|
120
|
+
const bufFunc = jsonl ? toJSONL : String;
|
|
121
|
+
const buf = Buffer.from(bufFunc(bufContent));
|
|
105
122
|
(0, _streamWrite.default)(this.input, buf, () => feed.end());
|
|
106
123
|
}
|
package/lib/obj-standardize.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ezs/basics",
|
|
3
3
|
"description": "Basics statements for EZS",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.23.1",
|
|
5
5
|
"author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
|
|
6
6
|
"bugs": "https://github.com/Inist-CNRS/ezs/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"fetch-with-proxy": "3.0.1",
|
|
14
14
|
"flat": "5.0.2",
|
|
15
15
|
"get-stream": "6.0.1",
|
|
16
|
+
"higher-path": "1.0.0",
|
|
16
17
|
"lodash.escaperegexp": "4.1.2",
|
|
17
18
|
"lodash.get": "4.4.2",
|
|
18
19
|
"lodash.mapkeys": "4.6.0",
|
|
@@ -37,7 +38,7 @@
|
|
|
37
38
|
"directories": {
|
|
38
39
|
"test": "test"
|
|
39
40
|
},
|
|
40
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "c244731593d7181d55b1d0c20373e5a263f18f02",
|
|
41
42
|
"homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
|
|
42
43
|
"keywords": [
|
|
43
44
|
"ezs"
|