@ridi/parser-core
Advanced tools
Comparing version 0.5.7 to 0.5.8
@@ -18,2 +18,3 @@ 'use strict'; | ||
ENOFILE: { code: 'ENOFILE', format: 'ENOFILE: no such file. (path: {0})' }, | ||
EEXIST: { code: 'EEXIST', format: 'EEXIST: file or directory already exists. (path: {0})' }, | ||
EINVAL: { code: 'EINVAL', format: 'EINVAL: invalid {0}. ({1}: {2})' }, | ||
@@ -20,0 +21,0 @@ ENOELMT: { code: 'ENOELMT', format: 'ENOELMT: no such element. (element: {0}, path: {1})' }, |
@@ -79,3 +79,4 @@ 'use strict'; | ||
PARSE: 'parse', | ||
READ_ITEMS: 'readItems' | ||
READ_ITEMS: 'readItems', | ||
UNZIP: 'unzip' | ||
}); | ||
@@ -318,3 +319,3 @@ | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var tasks, context; | ||
var action, tasks, context; | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
@@ -324,7 +325,8 @@ while (1) { | ||
case 0: | ||
action = Action.PARSE; | ||
tasks = [].concat(this._parseBeforeTasks(), this._parseTasks(), this._parseAfterTasks()); | ||
context = options; | ||
this.onProgress(0, tasks.length, Action.PARSE); | ||
_context2.next = 5; | ||
this.onProgress(0, tasks.length, action); | ||
_context2.next = 6; | ||
return tasks.reduce(function (prevPromise, task, index) { | ||
@@ -338,3 +340,3 @@ var result = prevPromise.then((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() { | ||
fun = task.fun, name = task.name; | ||
message = Action.PARSE + ' - ' + name; | ||
message = action + ' - ' + name; | ||
_context.next = 4; | ||
@@ -353,11 +355,11 @@ return _this.logger.measure(fun, _this, [context], message); | ||
}))); | ||
_this.onProgress(index + 1, tasks.length, Action.PARSE); | ||
_this.onProgress(index + 1, tasks.length, action); | ||
return result; | ||
}, _promise2.default.resolve()); | ||
case 5: | ||
this.logger.result(Action.PARSE); | ||
case 6: | ||
this.logger.result(action); | ||
return _context2.abrupt('return', context); | ||
case 7: | ||
case 8: | ||
case 'end': | ||
@@ -435,2 +437,3 @@ return _context2.stop(); | ||
* @throws {Errors.ENOENT} no such file or directory | ||
* @throws {Errors.EEXIST} file or directory already exists | ||
* @see Parser.parseDefaultOptions.unzipPath | ||
@@ -589,3 +592,3 @@ * @see Parser.parseDefaultOptions.overwrite | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var tasks, context; | ||
var action, tasks, context; | ||
return _regenerator2.default.wrap(function _callee7$(_context7) { | ||
@@ -595,7 +598,8 @@ while (1) { | ||
case 0: | ||
action = Action.READ_ITEMS; | ||
tasks = [].concat(this._readBeforeTasks(), this._readTasks(), this._readAfterTasks()); | ||
context = [items, options]; | ||
this.onProgress(0, tasks.length, Action.READ_ITEMS); | ||
_context7.next = 5; | ||
this.onProgress(0, tasks.length, action); | ||
_context7.next = 6; | ||
return tasks.reduce(function (prevPromise, task, index) { | ||
@@ -609,3 +613,3 @@ var result = prevPromise.then((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6() { | ||
fun = task.fun, name = task.name; | ||
message = Action.READ_ITEMS + '(' + items.length + ') - ' + name; | ||
message = action + '(' + items.length + ') - ' + name; | ||
_context6.next = 4; | ||
@@ -624,11 +628,11 @@ return _this3.logger.measure(fun, _this3, (0, _typecheck.isArray)(context) ? context : [context], message); | ||
}))); | ||
_this3.onProgress(index + 1, tasks.length, Action.READ_ITEMS); | ||
_this3.onProgress(index + 1, tasks.length, action); | ||
return result; | ||
}, _promise2.default.resolve()); | ||
case 5: | ||
this.logger.result(Action.READ_ITEMS + '(' + items.length + ')'); | ||
case 6: | ||
this.logger.result(action + '(' + items.length + ')'); | ||
return _context7.abrupt('return', context); | ||
case 7: | ||
case 8: | ||
case 'end': | ||
@@ -746,2 +750,87 @@ return _context7.stop(); | ||
/** | ||
* @typedef UnzipTask | ||
* @property {function} fun Action executor | ||
* @property {string} name Action name | ||
*/ | ||
/** | ||
* @returns {UnzipTask[]} return tasks | ||
*/ | ||
Parser.prototype._unzipTasks = function _unzipTasks() { | ||
return [{ fun: this._prepareParse, name: 'prepareParse' }, { fun: this._unzipIfNeeded, name: 'unzipIfNeeded' }]; | ||
}; | ||
/** | ||
* @param {string} unzipPath | ||
* @param {boolean} overwrite | ||
* @returns {boolean} success | ||
* @throws {Errors.EINVAL} invalid options or value type | ||
* @throws {Errors.ENOENT} no such file or directory | ||
* @throws {Errors.ENOFILE} no such file | ||
*/ | ||
Parser.prototype.unzip = function () { | ||
var _ref10 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee11(unzipPath) { | ||
var _this5 = this; | ||
var overwrite = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
var action, tasks, context; | ||
return _regenerator2.default.wrap(function _callee11$(_context11) { | ||
while (1) { | ||
switch (_context11.prev = _context11.next) { | ||
case 0: | ||
action = Action.UNZIP; | ||
tasks = this._unzipTasks(); | ||
context = { unzipPath: unzipPath, overwrite: overwrite }; | ||
this.onProgress(0, tasks.length, action); | ||
_context11.next = 6; | ||
return tasks.reduce(function (prevPromise, task, index) { | ||
var result = prevPromise.then((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10() { | ||
var fun, name, message; | ||
return _regenerator2.default.wrap(function _callee10$(_context10) { | ||
while (1) { | ||
switch (_context10.prev = _context10.next) { | ||
case 0: | ||
fun = task.fun, name = task.name; | ||
message = action + ' - ' + name; | ||
_context10.next = 4; | ||
return _this5.logger.measure(fun, _this5, [context], message); | ||
case 4: | ||
context = _context10.sent; | ||
case 5: | ||
case 'end': | ||
return _context10.stop(); | ||
} | ||
} | ||
}, _callee10, _this5); | ||
}))); | ||
_this5.onProgress(index + 1, tasks.length, action); | ||
return result; | ||
}, _promise2.default.resolve()); | ||
case 6: | ||
this.logger.result(action); | ||
return _context11.abrupt('return', (0, _typecheck.isString)(this.input)); | ||
case 8: | ||
case 'end': | ||
return _context11.stop(); | ||
} | ||
} | ||
}, _callee11, this); | ||
})); | ||
function unzip(_x13) { | ||
return _ref10.apply(this, arguments); | ||
} | ||
return unzip; | ||
}(); | ||
return Parser; | ||
@@ -748,0 +837,0 @@ }(); |
@@ -75,3 +75,3 @@ 'use strict'; | ||
var overwrite = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
var writeFile; | ||
var flags, writeFile; | ||
return _regenerator2.default.wrap(function _callee3$(_context3) { | ||
@@ -86,8 +86,10 @@ while (1) { | ||
flags = overwrite ? 'w' : 'wx'; | ||
writeFile = function writeFile(entry, output) { | ||
return new _promise2.default(function (resolve) { | ||
var writeStream = _fsExtra2.default.createWriteStream(output, { encoding: 'binary' }); | ||
return new _promise2.default(function (resolve, reject) { | ||
var writeStream = _fsExtra2.default.createWriteStream(output, { encoding: 'binary', flags: flags }); | ||
var onError = function onError(error) { | ||
resolve(error); | ||
writeStream.end(); | ||
reject(error); | ||
}; | ||
@@ -116,3 +118,3 @@ writeStream.on('error', onError); | ||
_context3.next = 5; | ||
_context3.next = 6; | ||
return this.files.reduce(function (prevPromise, entry) { | ||
@@ -136,3 +138,3 @@ return prevPromise.then((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { | ||
if (entry.path.endsWith('/')) { | ||
_context2.next = 7; | ||
_context2.next = 8; | ||
break; | ||
@@ -147,7 +149,10 @@ } | ||
if (error) { | ||
_this2.logger.error(error); | ||
if (!error) { | ||
_context2.next = 8; | ||
break; | ||
} | ||
case 7: | ||
throw error; | ||
case 8: | ||
case 'end': | ||
@@ -161,3 +166,3 @@ return _context2.stop(); | ||
case 5: | ||
case 6: | ||
case 'end': | ||
@@ -164,0 +169,0 @@ return _context3.stop(); |
{ | ||
"name": "@ridi/parser-core", | ||
"version": "0.5.7", | ||
"version": "0.5.8", | ||
"description": "Utilities for parsers", | ||
@@ -5,0 +5,0 @@ "author": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76313
1909