@ridi/parser-core
Advanced tools
Comparing version 0.3.0-alpha.2 to 0.3.0-alpha.3
@@ -6,2 +6,3 @@ 'use strict'; | ||
}); | ||
exports.defaultBufferSize = undefined; | ||
@@ -32,2 +33,5 @@ var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
// https://nodejs.org/api/stream.html#stream_new_stream_readable_options | ||
var defaultBufferSize = exports.defaultBufferSize = 16384; | ||
var CryptoProvider = function () { | ||
@@ -46,3 +50,3 @@ function CryptoProvider() { | ||
/** | ||
* Update status by parser | ||
* Prefer buffer size | ||
*/ | ||
@@ -121,2 +125,12 @@ | ||
(0, _createClass3.default)(CryptoProvider, [{ | ||
key: 'bufferSize', | ||
get: function get() { | ||
return defaultBufferSize; | ||
} | ||
/** | ||
* Update status by parser | ||
*/ | ||
}, { | ||
key: 'status', | ||
@@ -142,3 +156,2 @@ set: function set(newStatus) { | ||
exports.default = CryptoProvider; | ||
module.exports = exports.default; | ||
exports.default = CryptoProvider; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.openZip = exports.validateOptions = exports.isUrl = exports.isString = exports.isObject = exports.isFunc = exports.isExists = exports.isBool = exports.isArray = exports.getType = exports.stringContains = exports.readEntries = exports.getPathes = exports.safePathJoin = exports.safePath = exports.safeDirname = exports.parseBool = exports.mergeObjects = exports.mustOverride = exports.createError = exports.Errors = exports.CryptoProvider = exports.Cryptor = undefined; | ||
exports.openZip = exports.validateOptions = exports.isUrl = exports.isString = exports.isObject = exports.isFunc = exports.isExists = exports.isBool = exports.isArray = exports.getType = exports.stringContains = exports.readEntries = exports.getPathes = exports.safePathJoin = exports.safePath = exports.safeDirname = exports.parseBool = exports.mergeObjects = exports.Logger = exports.mustOverride = exports.createError = exports.Errors = exports.CryptoProvider = exports.Cryptor = undefined; | ||
@@ -21,2 +21,6 @@ var _Cryptor = require('./Cryptor'); | ||
var _Logger = require('./Logger'); | ||
var _Logger2 = _interopRequireDefault(_Logger); | ||
var _mergeObjects = require('./mergeObjects'); | ||
@@ -57,2 +61,3 @@ | ||
exports.mustOverride = _errors.mustOverride; | ||
exports.Logger = _Logger2.default; | ||
exports.mergeObjects = _mergeObjects2.default; | ||
@@ -59,0 +64,0 @@ exports.parseBool = _parseBool2.default; |
@@ -11,2 +11,6 @@ 'use strict'; | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
@@ -28,2 +32,4 @@ | ||
var _CryptoProvider = require('./CryptoProvider'); | ||
var _pathUtil = require('./pathUtil'); | ||
@@ -91,3 +97,19 @@ | ||
_context.next = 2; | ||
return _fsExtra2.default.readFile(fullPath); | ||
return new _promise2.default(function (resolve, reject) { | ||
var bufferSize = (0, _typecheck.isExists)(cryptoProvider) ? cryptoProvider.bufferSize : _CryptoProvider.defaultBufferSize; | ||
var stream = _fsExtra2.default.createReadStream(fullPath, { highWaterMark: bufferSize, encoding: 'binary' }); | ||
var buffer = Buffer.from([]); | ||
stream.on('data', function (chunk) { | ||
chunk = Buffer.from(chunk, 'binary'); | ||
if ((0, _typecheck.isExists)(cryptoProvider)) { | ||
buffer = Buffer.concat([buffer, cryptoProvider.run(chunk, fullPath)]); | ||
} else { | ||
buffer = Buffer.concat([buffer, chunk]); | ||
} | ||
}).on('error', function (e) { | ||
return reject(e); | ||
}).on('end', function () { | ||
return resolve(buffer); | ||
}); | ||
}); | ||
@@ -97,15 +119,8 @@ case 2: | ||
file = (0, _typecheck.isExists)(cryptoProvider) ? cryptoProvider.run(file, fullPath) : file; | ||
if (!(0, _typecheck.isExists)(encoding)) { | ||
_context.next = 6; | ||
break; | ||
if ((0, _typecheck.isExists)(encoding)) { | ||
file = file.toString(encoding); | ||
} | ||
return _context.abrupt('return', file.toString(encoding)); | ||
case 6: | ||
return _context.abrupt('return', file); | ||
case 7: | ||
case 5: | ||
case 'end': | ||
@@ -112,0 +127,0 @@ return _context.stop(); |
@@ -11,2 +11,6 @@ 'use strict'; | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
@@ -16,6 +20,2 @@ | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
@@ -27,3 +27,5 @@ | ||
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(entry, encoding) { | ||
var buffer; | ||
var _this = this; | ||
var file; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
@@ -34,22 +36,28 @@ while (1) { | ||
_context.next = 2; | ||
return entry.buffer(); | ||
return new _promise2.default(function (resolve, reject) { | ||
var buffer = Buffer.from([]); | ||
entry.stream().setEncoding('binary').on('data', function (chunk) { | ||
chunk = Buffer.from(chunk, 'binary'); | ||
if ((0, _typecheck.isExists)(_this.cryptoProvider)) { | ||
buffer = Buffer.concat([buffer, _this.cryptoProvider.run(chunk, entry.path)]); | ||
} else { | ||
buffer = Buffer.concat([buffer, chunk]); | ||
} | ||
}).on('error', function (e) { | ||
_Logger2.default.error(e); | ||
reject(e); | ||
}).on('finish', function () { | ||
return resolve(buffer); | ||
}); | ||
}); | ||
case 2: | ||
buffer = _context.sent; | ||
file = _context.sent; | ||
if ((0, _typecheck.isExists)(this.cryptoProvider)) { | ||
buffer = this.cryptoProvider.run(buffer, entry.path); | ||
if ((0, _typecheck.isExists)(encoding)) { | ||
file = file.toString(encoding); | ||
} | ||
return _context.abrupt('return', file); | ||
if (!(0, _typecheck.isExists)(encoding)) { | ||
_context.next = 6; | ||
break; | ||
} | ||
return _context.abrupt('return', buffer.toString(encoding)); | ||
case 6: | ||
return _context.abrupt('return', buffer); | ||
case 7: | ||
case 5: | ||
case 'end': | ||
@@ -69,3 +77,3 @@ return _context.stop(); | ||
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(unzipPath) { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -86,12 +94,13 @@ var overwrite = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
return new _promise2.default(function (resolve, reject) { | ||
var writeStream = _fsExtra2.default.createWriteStream(output); | ||
var onError = function onError() { | ||
reject(); | ||
var writeStream = _fsExtra2.default.createWriteStream(output, { encoding: 'binary' }); | ||
var onError = function onError(e) { | ||
_Logger2.default.error(e); | ||
reject(e); | ||
writeStream.close(); | ||
}; | ||
entry.stream().on('data', function (data) { | ||
if ((0, _typecheck.isExists)(_this.cryptoProvider)) { | ||
writeStream.write(_this.cryptoProvider.run(data, entry.path)); | ||
entry.stream().on('data', function (chunk) { | ||
if ((0, _typecheck.isExists)(_this2.cryptoProvider)) { | ||
writeStream.write(_this2.cryptoProvider.run(chunk, entry.path)); | ||
} else { | ||
writeStream.write(data); | ||
writeStream.write(chunk); | ||
} | ||
@@ -103,3 +112,3 @@ }).on('error', onError).on('finish', function () { | ||
writeStream.on('close', function () { | ||
resolve(); | ||
return resolve(); | ||
}); | ||
@@ -135,3 +144,3 @@ }); | ||
} | ||
}, _callee2, _this); | ||
}, _callee2, _this2); | ||
}))); | ||
@@ -165,2 +174,6 @@ }, _promise2.default.resolve()); | ||
var _Logger = require('./Logger'); | ||
var _Logger2 = _interopRequireDefault(_Logger); | ||
var _typecheck = require('./typecheck'); | ||
@@ -167,0 +180,0 @@ |
{ | ||
"name": "@ridi/parser-core", | ||
"version": "0.3.0-alpha.2", | ||
"version": "0.3.0-alpha.3", | ||
"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
39926
35
16
1000