@ezs/basics 2.9.1 → 2.10.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/README.md CHANGED
@@ -19,6 +19,7 @@ npm install @ezs/basics
19
19
  * [CSVObject](#csvobject)
20
20
  * [CSVParse](#csvparse)
21
21
  * [CSVString](#csvstring)
22
+ * [DataURLParse](#dataurlparse)
22
23
  * [FILELoad](#fileload)
23
24
  * [FILEMerge](#filemerge)
24
25
  * [FILESave](#filesave)
@@ -215,6 +216,16 @@ a;b;c
215
216
 
216
217
  Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
217
218
 
219
+ ### DataURLParse
220
+
221
+ Take an URL `String`, parse it as a data URLs, return `Object`.
222
+
223
+ See:
224
+
225
+ * <https://developer.mozilla.org/fr/docs/Web/URI/Reference/Schemes/data>
226
+
227
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
228
+
218
229
  ### FILELoad
219
230
 
220
231
  Take `Object` containing filename et throw content by chunk
@@ -742,6 +753,7 @@ Or if no target is specified, the output will be the returned content of URL.
742
753
  * `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** if present select value to send (by POST)
743
754
  * `target` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** choose the key to set
744
755
  * `json` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** parse as JSON the content of URL (optional, default `false`)
756
+ * `dataurl` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** encode content into DATA Url (optional, default `false`)
745
757
  * `timeout` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** timeout in milliseconds (optional, default `1000`)
746
758
  * `mimetype` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** mimetype for value of path (if presents) (optional, default `"application/json"`)
747
759
  * `noerror` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** ignore all errors, the target field will remain undefined (optional, default `false`)
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = DataURLParse;
7
+ var _url = require("url");
8
+ /**
9
+ * Take an URL `String`, parse it as a data URLs, return `Object`.
10
+ *
11
+ * See:
12
+ *
13
+ * - {@link https://developer.mozilla.org/fr/docs/Web/URI/Reference/Schemes/data}
14
+ *
15
+ * @name DataURLParse
16
+ * @returns {Object}
17
+ */
18
+ function DataURLParse(data, feed) {
19
+ if (this.isLast()) {
20
+ return feed.close();
21
+ }
22
+ const parts = String(data).split(',');
23
+ if (parts.length < 2) {
24
+ return feed.send(new Error('Invalid Data URL'));
25
+ }
26
+ return feed.send(Buffer.from(parts[1], 'base64'));
27
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = FILELoadParquet;
7
+ var _fs = require("fs");
8
+ var _path = require("path");
9
+ var _os = require("os");
10
+ var _higherPath = _interopRequireDefault(require("higher-path"));
11
+ var _hyparquet = require("hyparquet");
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
+ /**
14
+ * @name FileLoadParquet
15
+ * @param {String} [location=TMPDIR] Directory location
16
+ * @returns {Object}
17
+ */
18
+ async function FILELoadParquet(data, feed) {
19
+ if (this.isLast()) {
20
+ return feed.close();
21
+ }
22
+ const location = (0, _path.normalize)(this.getParam('location', '/'));
23
+ const locations = [(0, _higherPath.default)((0, _os.tmpdir)(), location), (0, _higherPath.default)(process.cwd(), location)];
24
+ const filename = locations.filter(Boolean).map(dir => (0, _path.resolve)(dir, String(data).trim())).filter(fil => (0, _fs.existsSync)(fil)).shift();
25
+ if (!filename) {
26
+ return feed.stop(new Error('File location check failed.'));
27
+ }
28
+ (0, _fs.accessSync)((0, _path.dirname)(filename), _fs.constants.R_OK | _fs.constants.W_OK);
29
+ (0, _fs.accessSync)(filename, _fs.constants.R_OK | _fs.constants.W_OK);
30
+ await (0, _hyparquet.parquetRead)({
31
+ file: await (0, _hyparquet.asyncBufferFromFile)(filename),
32
+ rowFormat: 'object',
33
+ onComplete: rows => feed.write(rows)
34
+ });
35
+ return feed.end();
36
+ }
37
+ ;
package/lib/index.js CHANGED
@@ -28,6 +28,7 @@ var _urlPagination = _interopRequireDefault(require("./url-pagination"));
28
28
  var _urlString = _interopRequireDefault(require("./url-string"));
29
29
  var _urlStream = _interopRequireDefault(require("./url-stream"));
30
30
  var _urlConnect = _interopRequireDefault(require("./url-connect"));
31
+ var _dataurlParse = _interopRequireDefault(require("./dataurl-parse"));
31
32
  var _txtZip = _interopRequireDefault(require("./txt-zip"));
32
33
  var _zipExtract = _interopRequireDefault(require("./zip-extract"));
33
34
  var _tarExtract = _interopRequireDefault(require("./tar-extract"));
@@ -62,6 +63,7 @@ const funcs = {
62
63
  URLString: _urlString.default,
63
64
  URLStream: _urlStream.default,
64
65
  URLConnect: _urlConnect.default,
66
+ DataURLParse: _dataurlParse.default,
65
67
  TXTZip: _txtZip.default,
66
68
  ZIPExtract: _zipExtract.default,
67
69
  TARExtract: _tarExtract.default,
@@ -5,8 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = OBJFlatten;
7
7
  var _flat = _interopRequireWildcard(require("flat"));
8
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
9
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
8
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
10
9
  /**
11
10
  * Flatten an `Object` with a path delimiting character.
12
11
  *
package/lib/url-fetch.js CHANGED
@@ -11,6 +11,8 @@ var _parseHeaders = _interopRequireDefault(require("parse-headers"));
11
11
  var _asyncRetry = _interopRequireDefault(require("async-retry"));
12
12
  var _request = _interopRequireDefault(require("./request"));
13
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ const createObjectURL = (arrayBuffer, mimeType = 'application/octet-stream') => `data:${mimeType};base64,${Buffer.from(arrayBuffer).toString('base64')}`;
15
+
14
16
  /**
15
17
  * Add a new field to an `Object`, with the returned content of URL.
16
18
  *
@@ -21,6 +23,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
21
23
  * @param {String} [path] if present select value to send (by POST)
22
24
  * @param {String} [target] choose the key to set
23
25
  * @param {String} [json=false] parse as JSON the content of URL
26
+ * @param {String} [dataurl=false] encode content into DATA Url
24
27
  * @param {Number} [timeout=1000] timeout in milliseconds
25
28
  * @param {String} [mimetype="application/json"] mimetype for value of path (if presents)
26
29
  * @param {Boolean} [noerror=false] ignore all errors, the target field will remain undefined
@@ -31,10 +34,11 @@ async function URLFetch(data, feed) {
31
34
  if (this.isLast()) {
32
35
  return feed.close();
33
36
  }
34
- const url = this.getParam('url');
37
+ const location = this.getParam('url');
35
38
  const path = this.getParam('path');
36
39
  const target = [].concat(this.getParam('target')).filter(Boolean).shift();
37
40
  const json = Boolean(this.getParam('json', false));
41
+ const dataurl = Boolean(this.getParam('dataurl', false));
38
42
  const retries = Number(this.getParam('retries', 5));
39
43
  const noerror = Boolean(this.getParam('noerror', false));
40
44
  const timeout = Number(this.getParam('timeout')) || 1000;
@@ -57,9 +61,16 @@ async function URLFetch(data, feed) {
57
61
  (0, _lodash.set)(parameters, 'headers.content-type', mimetype);
58
62
  }
59
63
  try {
60
- const response = await (0, _asyncRetry.default)((0, _request.default)(url, parameters), options);
61
- const func = json ? 'json' : 'text';
62
- const value = await response[func]();
64
+ const response = await (0, _asyncRetry.default)((0, _request.default)(location, parameters), options);
65
+ let value;
66
+ if (json) {
67
+ value = await response.json();
68
+ } else if (dataurl) {
69
+ const content = await response.arrayBuffer();
70
+ value = createObjectURL(content, response.headers.get('content-type'));
71
+ } else {
72
+ value = await response.text();
73
+ }
63
74
  if (target) {
64
75
  const result = typeof data === 'object' ? {
65
76
  ...data
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.9.1",
4
+ "version": "2.10.0",
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": "ff50bf461eed60cf72e17d7ab9fdeb5427bc5500",
38
+ "gitHead": "ef4ce5900d8256359040ab5a839f8768dbd4b8c3",
39
39
  "homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
40
40
  "keywords": [
41
41
  "ezs"