@ezs/basics 1.22.0 → 1.22.2

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,28 @@
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.22.2](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.22.1...@ezs/basics@1.22.2) (2022-09-14)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * 🐛 feed.flow return a Promise ([e73f140](https://github.com/Inist-CNRS/ezs/commit/e73f14042eb60b464c9e021345e479d24ba0ec81))
12
+
13
+
14
+
15
+
16
+
17
+ ## [1.22.1](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.22.0...@ezs/basics@1.22.1) (2022-09-07)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * 🐛 stop loop (and refactoring) ([2c162aa](https://github.com/Inist-CNRS/ezs/commit/2c162aa64a4603f79c5bdddbca8b58272278f745))
23
+
24
+
25
+
26
+
27
+
6
28
  # [1.22.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.21.0...@ezs/basics@1.22.0) (2022-09-05)
7
29
 
8
30
 
package/lib/file-load.js CHANGED
@@ -46,7 +46,7 @@ var _os = require("os");
46
46
  * @param {Boolean} [compress=false] Enable gzip compression
47
47
  * @returns {Object}
48
48
  */
49
- function FILELoad(data, feed) {
49
+ async function FILELoad(data, feed) {
50
50
  if (this.isLast()) {
51
51
  feed.close();
52
52
  return;
@@ -64,10 +64,7 @@ function FILELoad(data, feed) {
64
64
  return;
65
65
  }
66
66
 
67
- if (compress) {
68
- feed.flow((0, _fs.createReadStream)(file).pipe((0, _zlib.createGunzip)()));
69
- return;
70
- }
71
-
72
- feed.flow((0, _fs.createReadStream)(file));
67
+ const stream = compress ? (0, _fs.createReadStream)(file).pipe((0, _zlib.createGunzip)()) : (0, _fs.createReadStream)(file);
68
+ await feed.flow(stream);
69
+ return;
73
70
  }
package/lib/file-save.js CHANGED
@@ -19,6 +19,8 @@ var _makeDir = _interopRequireDefault(require("make-dir"));
19
19
 
20
20
  var _streamWrite = _interopRequireDefault(require("stream-write"));
21
21
 
22
+ var _debug = _interopRequireDefault(require("debug"));
23
+
22
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
25
 
24
26
  /**
@@ -56,8 +58,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
56
58
  * @param {Boolean} [compress=false] Enable gzip compression
57
59
  * @returns {Object}
58
60
  */
59
- async function FILESave(data, feed) {
60
- if (!this.handle) {
61
+ function FILESave(data, feed) {
62
+ const buf = Buffer.from(String(data));
63
+
64
+ if (this.isFirst()) {
61
65
  const identifier = String(this.getParam('identifier'));
62
66
  const location = this.getParam('location', (0, _os.tmpdir)());
63
67
  const compress = this.getParam('compress', false);
@@ -66,29 +70,37 @@ async function FILESave(data, feed) {
66
70
  _makeDir.default.sync(location);
67
71
  }
68
72
 
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
- }
78
- }
73
+ const name = compress ? `${identifier}.gz` : identifier;
79
74
 
80
- if (this.isLast()) {
81
- this.handleEnd.on('close', () => {
82
- (0, _fs.lstat)(this.filename, (err, stat) => {
83
- feed.write({
84
- filename: this.filename,
85
- ...stat
75
+ const filename = _path.default.resolve(location, name);
76
+
77
+ this.input = compress ? (0, _zlib.createGzip)() : (0, _fs.createWriteStream)(filename);
78
+ this.whenFinish = new Promise((resolve, reject) => {
79
+ const output = compress ? this.input.pipe((0, _fs.createWriteStream)(filename)) : this.input;
80
+ output.once('error', err => {
81
+ (0, _debug.default)('ezs')(`WARNING: ${filename} not saved. ${err}`);
82
+ reject(err);
83
+ });
84
+ output.once('close', () => {
85
+ (0, _debug.default)('ezs')(`${filename} saved.`);
86
+ (0, _fs.lstat)(filename, (err, stat) => {
87
+ if (err) {
88
+ return reject(err);
89
+ }
90
+
91
+ return resolve({
92
+ filename,
93
+ ...stat
94
+ });
86
95
  });
87
- return feed.close();
88
96
  });
89
97
  });
90
- return this.handle.end();
91
98
  }
92
99
 
93
- (0, _streamWrite.default)(this.handle, Buffer.from(String(data)), () => feed.end());
100
+ if (this.isLast()) {
101
+ this.input.end();
102
+ return this.whenFinish.then(stats => feed.write(stats)).catch(err => feed.stop(err)).finally(() => feed.close());
103
+ }
104
+
105
+ (0, _streamWrite.default)(this.input, buf, () => feed.end());
94
106
  }
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.22.0",
4
+ "version": "1.22.2",
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": "ae3bd633484915926ad8dac4040e191635939a7d",
39
+ "gitHead": "51729dbb9364dc2a882af2a3cbccbb2e79de89d2",
40
40
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
41
41
  "keywords": [
42
42
  "ezs"