Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ridi/parser-core

Package Overview
Dependencies
Maintainers
7
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ridi/parser-core - npm Package Compare versions

Comparing version 0.6.16-alpha.1 to 0.6.16-alpha.2

38

lib/readEntries.js

@@ -89,13 +89,29 @@ "use strict";

function fromZip(zip) {
return create(zip, Object.values(zip.files).reduce(function (entries, entry) {
return entries.concat([{
entryPath: entry.path,
getFile: function getFile(options) {
return zip.getFile(entry, options);
},
size: entry.uncompressedSize,
method: entry.compressionMethod,
extraFieldLength: entry.extraFieldLength
}]);
}, []));
var zipCopy = _objectSpread({}, zip);
zipCopy.files = zip.files.map(function (file) {
var getFile = function getFile() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var data = file.getData();
if (options.encoding) {
data = data.toString(options.encoding);
}
if (options.end) {
data = data.slice(0, options.end);
}
return data;
};
return _objectSpread(_objectSpread({}, file), {}, {
getFile: getFile,
entryPath: file.entryName,
size: file.header.size,
method: file.header.method,
extraFieldLength: file.extra.length
});
});
return create(zipCopy, zipCopy.files);
}

@@ -102,0 +118,0 @@

"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

@@ -10,4 +12,2 @@

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

@@ -19,8 +19,8 @@

var _path = _interopRequireDefault(require("path"));
var _streamChopper = _interopRequireDefault(require("stream-chopper"));
var _unzipper = _interopRequireDefault(require("unzipper"));
var _admZip = _interopRequireDefault(require("adm-zip"));
var _stream = require("stream");
var _bufferUtil = require("./bufferUtil");

@@ -36,13 +36,10 @@

var _pathUtil = require("./pathUtil");
var _streamUtil = require("./streamUtil");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
var _errors = _interopRequireWildcard(require("./errors"));
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
/* eslint-disable max-len */
function find(entryPath) {
return this.files.find(function (entry) {
return entryPath === entry.path;
return entryPath === entry.entryName;
});

@@ -85,4 +82,6 @@ }

var data = Buffer.from([]);
entry.stream() // is DuplexStream.
.pipe((0, _streamUtil.conditionally)((0, _typecheck.isExists)(bufferSize), new _streamChopper["default"]({
var readable = _stream.Readable.from(entry.getData());
readable.pipe((0, _streamUtil.conditionally)((0, _typecheck.isExists)(bufferSize), new _streamChopper["default"]({
size: Math.min(bufferSize, entry.uncompressedSize)

@@ -145,4 +144,3 @@ }))).pipe((0, _streamUtil.conditionally)((0, _typecheck.isExists)(end), (0, _createSliceStream["default"])(0, end))).pipe((0, _streamUtil.conditionally)(_this.cryptoProvider && !!_this.cryptoProvider.isStreamMode, (0, _createCryptoStream["default"])(entry.path, totalSize, _this.cryptoProvider, _CryptoProvider["default"].Purpose.READ_IN_ZIP))).on('data', function (chunk) {

var overwrite,
flags,
writeFile,
zip,
_args3 = arguments;

@@ -161,63 +159,6 @@ return _regenerator["default"].wrap(function _callee3$(_context3) {

flags = overwrite ? 'w' : 'wx';
writeFile = function writeFile(entry, output) {
return new Promise(function (resolve, reject) {
var bufferSize = _getBufferSize(_this2.cryptoProvider);
var writeStream = _fsExtra["default"].createWriteStream(output, {
encoding: 'binary',
flags: flags
});
var onError = function onError(error) {
writeStream.end();
reject(error);
};
var data = Buffer.from([]);
writeStream.on('error', onError);
writeStream.on('close', resolve); // Stream is DuplexStream.
var stream = entry.stream().pipe((0, _streamUtil.conditionally)((0, _typecheck.isExists)(bufferSize), new _streamChopper["default"]({
size: Math.min(bufferSize, entry.uncompressedSize)
}))).on('error', onError).on('data', function (chunk) {
/* istanbul ignore if */
if (_this2.cryptoProvider && !!_this2.cryptoProvider.isStreamMode) {
/* istanbul ignore next */
chunk = _this2.cryptoProvider.run(chunk, entry.path, _CryptoProvider["default"].Purpose.WRITE);
writeStream.write(chunk);
} else {
data = Buffer.concat([data, chunk]);
}
}).on('end', function () {
// Retain a reference to buffer so that it can't be GC'ed too soon.
// Otherwise, EBADF occurs.
// https://github.com/nodejs/node/blob/v10.15.0/lib/fs.js#L462
setTimeout(function () {
stream; // eslint-disable-line no-unused-expressions
}, 200);
if (_this2.cryptoProvider && !_this2.cryptoProvider.isStreamMode) {
data = _this2.cryptoProvider.run(data, entry.path, _CryptoProvider["default"].Purpose.WRITE);
if (Promise.resolve(data) === data) {
data.then(function (result) {
writeStream.write(result);
writeStream.end();
});
return;
}
}
writeStream.write(data);
writeStream.end();
});
});
};
_context3.next = 7;
return this.files.reduce(function (prevPromise, entry) {
return prevPromise.then( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
var output, dir, error;
zip = new _admZip["default"]();
_context3.next = 6;
return Promise.all(this.files.map( /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(entry) {
return _regenerator["default"].wrap(function _callee2$(_context2) {

@@ -227,31 +168,20 @@ while (1) {

case 0:
output = (0, _pathUtil.safePathJoin)(unzipPath, entry.path);
if (entry.path.split('/').length > 1) {
dir = _path["default"].dirname(output);
if (!_fsExtra["default"].existsSync(dir)) {
_fsExtra["default"].mkdirpSync(dir);
}
}
if (entry.path.endsWith('/')) {
_context2.next = 8;
if (!(_this2.cryptoProvider && !entry.isDirectory)) {
_context2.next = 6;
break;
}
_context2.next = 5;
return writeFile(entry, output);
_context2.t0 = entry;
_context2.next = 4;
return _this2.cryptoProvider.run(entry.getData(), entry.entryPath, _CryptoProvider["default"].Purpose.WRITE);
case 5:
error = _context2.sent;
case 4:
_context2.t1 = _context2.sent;
if (!error) {
_context2.next = 8;
break;
}
_context2.t0.setData.call(_context2.t0, _context2.t1);
throw error;
case 6:
zip.addFile(entry.entryName, entry.getData());
case 8:
case 7:
case "end":

@@ -262,5 +192,12 @@ return _context2.stop();

}, _callee2);
})));
}, Promise.resolve());
}));
return function (_x6) {
return _ref.apply(this, arguments);
};
}()));
case 6:
zip.extractAllTo(unzipPath);
case 7:

@@ -282,3 +219,3 @@ case "end":

_openZip = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(file, cryptoProvider, logger) {
var open, zip;
var files;
return _regenerator["default"].wrap(function _callee4$(_context4) {

@@ -288,10 +225,7 @@ while (1) {

case 0:
open = !(0, _typecheck.isString)(file) ? _unzipper["default"].Open.buffer : _unzipper["default"].Open.file;
_context4.next = 3;
return open(file);
case 3:
zip = _context4.sent;
zip.cryptoProvider = cryptoProvider;
return _context4.abrupt("return", _objectSpread(_objectSpread({}, zip), {}, {
_context4.prev = 0;
files = new _admZip["default"](file).getEntries();
return _context4.abrupt("return", {
files: files,
cryptoProvider: cryptoProvider,
find: find,

@@ -301,5 +235,10 @@ getFile: getFile,

logger: logger
}));
});
case 6:
case 5:
_context4.prev = 5;
_context4.t0 = _context4["catch"](0);
throw (0, _errors.createError)(_errors["default"].ENOENT, file);
case 8:
case "end":

@@ -309,3 +248,3 @@ return _context4.stop();

}
}, _callee4);
}, _callee4, null, [[0, 5]]);
}));

@@ -312,0 +251,0 @@ return _openZip.apply(this, arguments);

{
"name": "@ridi/parser-core",
"version": "0.6.16-alpha.1",
"version": "0.6.16-alpha.2",
"description": "Utilities for parsers",

@@ -21,2 +21,3 @@ "author": {

"dependencies": {
"adm-zip": "^0.4.16",
"crypto-js": "^4.0.0",

@@ -28,6 +29,5 @@ "event-stream": "3.3.4",

"string-format": "^2.0.0",
"string-natural-compare": "^3.0.1",
"unzipper": "^0.10.11"
"string-natural-compare": "^3.0.1"
},
"gitHead": "d9bbe7b40a8f4e83c329c1ffd9a542473aee2fad"
"gitHead": "c734756b2eed2da228f3269a4ad132f534af9d35"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc