@ezs/basics 1.17.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 CHANGED
@@ -3,6 +3,39 @@
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
+
17
+ # [1.18.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.17.1...@ezs/basics@1.18.0) (2022-06-21)
18
+
19
+
20
+ ### Features
21
+
22
+ * 🎸 add [FILESave] ([2e7dfd7](https://github.com/Inist-CNRS/ezs/commit/2e7dfd76f769418a56f7b9b6cb23d156f37b6789))
23
+
24
+
25
+
26
+
27
+
28
+ ## [1.17.1](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.17.0...@ezs/basics@1.17.1) (2022-04-01)
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * erratic error with store ([a26febc](https://github.com/Inist-CNRS/ezs/commit/a26febc4fe7bc0a66a7d32781dc6ef175f707f0a))
34
+
35
+
36
+
37
+
38
+
6
39
  # [1.17.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.16.0...@ezs/basics@1.17.0) (2022-03-25)
7
40
 
8
41
 
package/README.md CHANGED
@@ -18,6 +18,7 @@ npm install @ezs/basics
18
18
  - [CSVObject](#csvobject)
19
19
  - [CSVParse](#csvparse)
20
20
  - [CSVString](#csvstring)
21
+ - [FILESave](#filesave)
21
22
  - [INIString](#inistring)
22
23
  - [JSONParse](#jsonparse)
23
24
  - [JSONString](#jsonstring)
@@ -189,6 +190,44 @@ a;b;c
189
190
 
190
191
  Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
191
192
 
193
+ ### FILESave
194
+
195
+ Take data, convert it to buffer and append it to file
196
+
197
+ ##### Example
198
+
199
+ Input:
200
+
201
+ ```json
202
+ [
203
+ {"a": "a"},
204
+ {"a": "b"},
205
+ {"a": "c" }
206
+ ]
207
+ ```
208
+
209
+ Script:
210
+
211
+ ```ini
212
+ [FILESave]
213
+ location = /tmp
214
+ identifier = toto
215
+ ```
216
+
217
+ Output:
218
+
219
+ ```json
220
+ [{ filename: "/tmp/toto", size: XXX, ... }]
221
+ ```
222
+
223
+ #### Parameters
224
+
225
+ - `location` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Directory location (optional, default `TMPDIR`)
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`)
228
+
229
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
230
+
192
231
  ### INIString
193
232
 
194
233
  Take `Object` and generate INI
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = FILESave;
7
+
8
+ var _fs = require("fs");
9
+
10
+ var _zlib = require("zlib");
11
+
12
+ var _path = _interopRequireDefault(require("path"));
13
+
14
+ var _os = require("os");
15
+
16
+ var _pathExists = _interopRequireDefault(require("path-exists"));
17
+
18
+ var _makeDir = _interopRequireDefault(require("make-dir"));
19
+
20
+ var _streamWrite = _interopRequireDefault(require("stream-write"));
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
24
+ /**
25
+ * Take data, convert it to buffer and append it to file
26
+ *
27
+ * #### Example
28
+ *
29
+ * Input:
30
+ *
31
+ * ```json
32
+ * [
33
+ * {"a": "a"},
34
+ * {"a": "b"},
35
+ * {"a": "c" }
36
+ * ]
37
+ * ```
38
+ *
39
+ * Script:
40
+ *
41
+ * ```ini
42
+ * [FILESave]
43
+ * location = /tmp
44
+ * identifier = toto
45
+ * ```
46
+ *
47
+ * Output:
48
+ *
49
+ * ```json
50
+ * [{ filename: "/tmp/toto", size: XXX, ... }]
51
+ * ```
52
+ *
53
+ * @name FILESave
54
+ * @param {String} [location=TMPDIR] Directory location
55
+ * @param {String} [identifier] File name
56
+ * @param {Boolean} [compress=false] Enable gzip compression
57
+ * @returns {Object}
58
+ */
59
+ async function FILESave(data, feed) {
60
+ if (!this.handle) {
61
+ const identifier = String(this.getParam('identifier'));
62
+ const location = this.getParam('location', (0, _os.tmpdir)());
63
+ const compress = this.getParam('compress', false);
64
+
65
+ if (!_pathExists.default.sync(location)) {
66
+ _makeDir.default.sync(location);
67
+ }
68
+
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
+ }
79
+
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
86
+ });
87
+ return feed.close();
88
+ });
89
+ });
90
+ return this.handle.end();
91
+ }
92
+
93
+ (0, _streamWrite.default)(this.handle, Buffer.from(String(data)), () => feed.end());
94
+ }
package/lib/index.js CHANGED
@@ -53,6 +53,8 @@ var _zipExtract = _interopRequireDefault(require("./zip-extract"));
53
53
 
54
54
  var _iniString = _interopRequireDefault(require("./ini-string"));
55
55
 
56
+ var _fileSave = _interopRequireDefault(require("./file-save"));
57
+
56
58
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
57
59
 
58
60
  const funcs = {
@@ -80,6 +82,7 @@ const funcs = {
80
82
  TXTZip: _txtZip.default,
81
83
  ZIPExtract: _zipExtract.default,
82
84
  INIString: _iniString.default,
85
+ FILESave: _fileSave.default,
83
86
  // aliases
84
87
  bufferify: _bufObject.default.BUFObject,
85
88
  concat: _txtConcat.default.TXTConcat,
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.17.0",
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": {
@@ -18,9 +18,11 @@
18
18
  "lodash.mapvalues": "4.6.0",
19
19
  "lodash.set": "4.3.2",
20
20
  "lodash.zipobject": "4.1.3",
21
+ "make-dir": "3.1.0",
21
22
  "micromatch": "4.0.4",
22
23
  "node-abort-controller": "1.1.0",
23
24
  "parse-headers": "2.0.4",
25
+ "path-exists": "4.0.0",
24
26
  "stream-write": "1.0.1",
25
27
  "tmp-filepath": "2.0.0",
26
28
  "unzipper": "0.10.11",
@@ -34,7 +36,7 @@
34
36
  "directories": {
35
37
  "test": "test"
36
38
  },
37
- "gitHead": "7c26e58f03f6675d98f22914cf5e315a89916e2e",
39
+ "gitHead": "2003a35bd4f57965f324309db6cb0cb2afbeefbc",
38
40
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
39
41
  "keywords": [
40
42
  "ezs"