@ezs/basics 1.18.0 → 1.19.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 +3 -2
- package/lib/file-save.js +23 -10
- package/package.json +2 -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
|
+
# [1.19.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.18.0...@ezs/basics@1.19.0) (2022-06-22)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* 🎸 file save gz ([33df6cd](https://github.com/Inist-CNRS/ezs/commit/33df6cdc40af50c10511cca1449c5edb3a6878f2))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [1.18.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.17.1...@ezs/basics@1.18.0) (2022-06-21)
|
|
7
18
|
|
|
8
19
|
|
package/README.md
CHANGED
|
@@ -217,13 +217,14 @@ identifier = toto
|
|
|
217
217
|
Output:
|
|
218
218
|
|
|
219
219
|
```json
|
|
220
|
-
["/tmp/
|
|
220
|
+
[{ filename: "/tmp/toto", size: XXX, ... }]
|
|
221
221
|
```
|
|
222
222
|
|
|
223
223
|
#### Parameters
|
|
224
224
|
|
|
225
225
|
- `location` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Directory location (optional, default `TMPDIR`)
|
|
226
|
-
- `identifier` **[
|
|
226
|
+
- `identifier` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** File name
|
|
227
|
+
- `compress` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Enable gzip compression (optional, default `false`)
|
|
227
228
|
|
|
228
229
|
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
|
229
230
|
|
package/lib/file-save.js
CHANGED
|
@@ -7,6 +7,8 @@ exports.default = FILESave;
|
|
|
7
7
|
|
|
8
8
|
var _fs = require("fs");
|
|
9
9
|
|
|
10
|
+
var _zlib = require("zlib");
|
|
11
|
+
|
|
10
12
|
var _path = _interopRequireDefault(require("path"));
|
|
11
13
|
|
|
12
14
|
var _os = require("os");
|
|
@@ -45,36 +47,47 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
45
47
|
* Output:
|
|
46
48
|
*
|
|
47
49
|
* ```json
|
|
48
|
-
* ["/tmp/
|
|
50
|
+
* [{ filename: "/tmp/toto", size: XXX, ... }]
|
|
49
51
|
* ```
|
|
50
52
|
*
|
|
51
53
|
* @name FILESave
|
|
52
54
|
* @param {String} [location=TMPDIR] Directory location
|
|
53
|
-
* @param {
|
|
55
|
+
* @param {String} [identifier] File name
|
|
56
|
+
* @param {Boolean} [compress=false] Enable gzip compression
|
|
54
57
|
* @returns {Object}
|
|
55
58
|
*/
|
|
56
59
|
async function FILESave(data, feed) {
|
|
57
60
|
if (!this.handle) {
|
|
58
61
|
const identifier = String(this.getParam('identifier'));
|
|
59
62
|
const location = this.getParam('location', (0, _os.tmpdir)());
|
|
63
|
+
const compress = this.getParam('compress', false);
|
|
60
64
|
|
|
61
65
|
if (!_pathExists.default.sync(location)) {
|
|
62
66
|
_makeDir.default.sync(location);
|
|
63
67
|
}
|
|
64
68
|
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
if (compress) {
|
|
70
|
+
this.filename = _path.default.resolve(location, `${identifier}.gz`);
|
|
71
|
+
this.handle = (0, _zlib.createGzip)();
|
|
72
|
+
this.handleEnd = this.handle.pipe((0, _fs.createWriteStream)(this.filename));
|
|
73
|
+
} else {
|
|
74
|
+
this.filename = _path.default.resolve(location, identifier);
|
|
75
|
+
this.handle = (0, _fs.createWriteStream)(this.filename);
|
|
76
|
+
this.handleEnd = this.handle;
|
|
77
|
+
}
|
|
67
78
|
}
|
|
68
79
|
|
|
69
80
|
if (this.isLast()) {
|
|
70
|
-
this.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
81
|
+
this.handleEnd.on('close', () => {
|
|
82
|
+
(0, _fs.lstat)(this.filename, (err, stat) => {
|
|
83
|
+
feed.write({
|
|
84
|
+
filename: this.filename,
|
|
85
|
+
...stat
|
|
86
|
+
});
|
|
87
|
+
return feed.close();
|
|
75
88
|
});
|
|
76
|
-
return feed.close();
|
|
77
89
|
});
|
|
90
|
+
return this.handle.end();
|
|
78
91
|
}
|
|
79
92
|
|
|
80
93
|
(0, _streamWrite.default)(this.handle, Buffer.from(String(data)), () => feed.end());
|
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.19.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": "2003a35bd4f57965f324309db6cb0cb2afbeefbc",
|
|
40
40
|
"homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
|
|
41
41
|
"keywords": [
|
|
42
42
|
"ezs"
|