@ezs/basics 2.5.5 → 2.5.7

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/README.md CHANGED
@@ -552,6 +552,7 @@ Take all recevied objects and build a tar file
552
552
  - `location` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Location path to store files in the tarball (optional, default `data`)
553
553
  - `json` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Convert to JSON the content of each chunk (optional, default `true`)
554
554
  - `extension` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Choose extension fo each file (optional, default `json`)
555
+ - `additionalFile` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Path to an additional file that will be add to tarball
555
556
  - `compress` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Enable gzip compression (optional, default `false`)
556
557
 
557
558
  ### TARExtract
@@ -730,14 +731,10 @@ The output will be the returned content of URL.
730
731
 
731
732
  Useful to send JSON data to an API and get results.
732
733
 
733
- Warning :
734
- if retries === 1, it will directly use the stream
735
- to connect to the server otherwise the stream will be fully
736
- read to be buffered and sent to the server (n times)
737
-
738
734
  #### Parameters
739
735
 
740
736
  - `url` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** URL to fetch
737
+ - `streaming` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Direct connection to the Object Stream server (disables the retries setting) (optional, default `false`)
741
738
  - `json` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Parse as JSON the content of URL (optional, default `false`)
742
739
  - `timeout` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Timeout in milliseconds (optional, default `1000`)
743
740
  - `noerror` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Ignore all errors (optional, default `false`)
package/lib/tar-dump.js CHANGED
@@ -4,10 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = TARDump;
7
+ var _path = require("path");
8
+ var _util = require("util");
9
+ var _fs = require("fs");
7
10
  var _tarStream = _interopRequireDefault(require("tar-stream"));
8
11
  var _zlib = require("zlib");
9
12
  var _lodash = _interopRequireDefault(require("lodash.merge"));
10
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ // Avoid importing from fs/promise to be compatible with node 12
15
+ const readFilePromise = (0, _util.promisify)(_fs.readFile);
11
16
  const eol = '\n';
12
17
 
13
18
  /**
@@ -23,6 +28,7 @@ const eol = '\n';
23
28
  * @param {String} [location=data] Location path to store files in the tarball
24
29
  * @param {String} [json=true] Convert to JSON the content of each chunk
25
30
  * @param {String} [extension=json] Choose extension fo each file
31
+ * @param {String} [additionalFile] Path to an additional file that will be add to tarball
26
32
  * @param {Boolean} [compress=false] Enable gzip compression
27
33
  */
28
34
  function TARDump(data, feed) {
@@ -46,7 +52,10 @@ function TARDump(data, feed) {
46
52
  this.pack.entry({
47
53
  name: 'manifest.json'
48
54
  }, JSON.stringify(manifest, null, ' '));
49
- this.pack.finalize();
55
+ const additionalFiles = [].concat(this.getParam('additionalFile')).filter(Boolean).map(filename => this.ezs.getPath().map(dir => (0, _path.resolve)(dir, filename)).filter(Boolean).shift()).filter(Boolean).map(fullfilename => readFilePromise(fullfilename).then(fileContent => this.pack.entry({
56
+ name: (0, _path.basename)(fullfilename)
57
+ }, fileContent)));
58
+ Promise.all(additionalFiles).catch(e => feed.stop(e)).finally(() => this.pack.finalize());
50
59
  return;
51
60
  }
52
61
  const json = this.getParam('json', true);
@@ -21,13 +21,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
21
21
  *
22
22
  * Useful to send JSON data to an API and get results.
23
23
  *
24
- * Warning :
25
- * if retries === 1, it will directly use the stream
26
- * to connect to the server otherwise the stream will be fully
27
- * read to be buffered and sent to the server (n times)
28
- *
29
24
  * @name URLConnect
30
25
  * @param {String} [url] URL to fetch
26
+ * @param {String} [streaming=false] Direct connection to the Object Stream server (disables the retries setting)
31
27
  * @param {String} [json=false] Parse as JSON the content of URL
32
28
  * @param {Number} [timeout=1000] Timeout in milliseconds
33
29
  * @param {Boolean} [noerror=false] Ignore all errors
@@ -37,6 +33,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
37
33
  */
38
34
  async function URLConnect(data, feed) {
39
35
  const url = this.getParam('url');
36
+ const streaming = Boolean(this.getParam('streaming', false));
40
37
  const retries = Number(this.getParam('retries', 5));
41
38
  const noerror = Boolean(this.getParam('noerror', false));
42
39
  const json = this.getParam('json', true);
@@ -53,7 +50,7 @@ async function URLConnect(data, feed) {
53
50
  (0, _streamWrite.default)(this.input, data, () => feed.end());
54
51
  const streamIn = this.input.pipe(ezs(encoder));
55
52
  let bodyIn;
56
- if (retries === 1) {
53
+ if (streaming) {
57
54
  bodyIn = streamIn.pipe(ezs.toBuffer());
58
55
  } else {
59
56
  bodyIn = await (0, _getStream.default)(streamIn);
@@ -81,24 +78,22 @@ async function URLConnect(data, feed) {
81
78
  err.responseText = text;
82
79
  throw err;
83
80
  }
84
- if (retries === 1) {
81
+ if (streaming) {
85
82
  const bodyOut = json ? response.body.pipe(_JSONStream.default.parse('*')) : response.body;
86
83
  bodyOut.once('error', e => {
87
84
  controller.abort();
88
85
  output.emit('error', e);
89
86
  });
90
- bodyOut.pipe(output);
91
- } else {
92
- if (json) {
93
- const bodyOutRaw = await (0, _getStream.default)(response.body);
94
- const bodyOutArray = JSON.parse(bodyOutRaw);
95
- (0, _from.default)(bodyOutArray).pipe(output);
96
- } else {
97
- response.body.pipe(output);
98
- }
87
+ return bodyOut.pipe(output);
88
+ }
89
+ if (json) {
90
+ const bodyOutRaw = await (0, _getStream.default)(response.body);
91
+ const bodyOutArray = JSON.parse(bodyOutRaw);
92
+ return (0, _from.default)(bodyOutArray).pipe(output);
99
93
  }
94
+ return response.body.pipe(output);
100
95
  }, {
101
- retries
96
+ retries: streaming ? 0 : retries
102
97
  });
103
98
  } catch (e) {
104
99
  if (!noerror) {
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.5.5",
4
+ "version": "2.5.7",
5
5
  "author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
6
6
  "bugs": "https://github.com/Inist-CNRS/ezs/issues",
7
7
  "dependencies": {
@@ -41,7 +41,7 @@
41
41
  "directories": {
42
42
  "test": "test"
43
43
  },
44
- "gitHead": "f168e4c0002e2eb1865ae7eacda04f94904b37cd",
44
+ "gitHead": "0667dffb8743f46bdd5cfab7d1cf47801db925c3",
45
45
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
46
46
  "keywords": [
47
47
  "ezs"