@ezs/basics 2.8.2 → 2.9.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/README.md CHANGED
@@ -320,6 +320,7 @@ Output:
320
320
  * `content` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Content to save instead of using input object
321
321
  * `jsonl` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Save as json line (optional, default `false`)
322
322
  * `compress` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Enable gzip compression (optional, default `false`)
323
+ * `append` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Enable append mode (add content to an existing file) (optional, default `false`)
323
324
 
324
325
  Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
325
326
 
package/lib/file-save.js CHANGED
@@ -50,6 +50,7 @@ const toJSONL = line => JSON.stringify(line).concat(eol);
50
50
  * @param {String} [content] Content to save instead of using input object
51
51
  * @param {Boolean} [jsonl=false] Save as json line
52
52
  * @param {Boolean} [compress=false] Enable gzip compression
53
+ * @param {Boolean} [append=false] Enable append mode (add content to an existing file)
53
54
  * @returns {Object}
54
55
  */
55
56
  function FILESave(data, feed) {
@@ -57,6 +58,7 @@ function FILESave(data, feed) {
57
58
  const identifier = String(this.getParam('identifier'));
58
59
  const location = _path.default.normalize(this.getParam('location', (0, _os.tmpdir)()));
59
60
  const compress = this.getParam('compress', false);
61
+ const flags = Boolean(this.getParam('append', false)) ? 'a' : 'w';
60
62
  if (location.indexOf((0, _os.tmpdir)()) !== 0 && location.indexOf(process.cwd()) !== 0) {
61
63
  feed.stop(new Error('File location check failed.'));
62
64
  return;
@@ -67,7 +69,9 @@ function FILESave(data, feed) {
67
69
  (0, _fs.accessSync)(location, _fs.constants.R_OK | _fs.constants.W_OK);
68
70
  const name = compress ? `${identifier}.gz` : identifier;
69
71
  const filename = _path.default.resolve(location, name);
70
- this.input = compress ? (0, _zlib.createGzip)() : (0, _fs.createWriteStream)(filename);
72
+ this.input = compress ? (0, _zlib.createGzip)() : (0, _fs.createWriteStream)(filename, {
73
+ flags
74
+ });
71
75
  this.whenFinish = new Promise((resolve, reject) => {
72
76
  const output = compress ? this.input.pipe((0, _fs.createWriteStream)(filename)) : this.input;
73
77
  output.once('error', err => {
package/lib/request.js CHANGED
@@ -6,12 +6,17 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _fetchWithProxy = _interopRequireDefault(require("fetch-with-proxy"));
8
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
- const request = (url, parameters) => async () => {
9
+ const request = (url, parameters) => async bail => {
10
10
  const response = await (0, _fetchWithProxy.default)(url, parameters);
11
11
  if (!response.ok) {
12
+ // response.status >= 200 && response.status < 300
12
13
  const err = new Error(response.statusText);
13
14
  const text = await response.text();
14
15
  err.responseText = text;
16
+ if ([400, 401, 402, 403, 404].indexOf(response.status) >= 0) {
17
+ // useless to retry
18
+ return bail(err);
19
+ }
15
20
  throw err;
16
21
  }
17
22
  return response;
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.8.2",
4
+ "version": "2.9.1",
5
5
  "author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
6
6
  "bugs": "https://github.com/Inist-CNRS/ezs/issues",
7
7
  "dependencies": {
@@ -35,7 +35,7 @@
35
35
  "directories": {
36
36
  "test": "test"
37
37
  },
38
- "gitHead": "037710b96f0d99070ce1ab92522b41262deefe69",
38
+ "gitHead": "ff50bf461eed60cf72e17d7ab9fdeb5427bc5500",
39
39
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
40
40
  "keywords": [
41
41
  "ezs"