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

@loaders.gl/zip

Package Overview
Dependencies
Maintainers
9
Versions
332
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@loaders.gl/zip - npm Package Compare versions

Comparing version 1.3.3 to 2.0.0-alpha.1

111

dist/es5/zip-loader.js

@@ -10,2 +10,6 @@ "use strict";

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _jszip = _interopRequireDefault(require("jszip"));

@@ -18,2 +22,3 @@

category: 'archive',
test: 'PK',
parse: parseZipAsync

@@ -23,27 +28,85 @@ };

function parseZipAsync(data, options) {
var promises = [];
var fileMap = {};
var jsZip = new _jszip["default"]();
return jsZip.loadAsync(data, options).then(function (zip) {
zip.forEach(function (relativePath, zipEntry) {
var subFilename = zipEntry.name;
var promise = jsZip.file(subFilename).async(options.dataType || 'arraybuffer').then(function (arrayBuffer) {
fileMap[relativePath] = arrayBuffer;
})["catch"](function (error) {
options.log.error("Unable to read ".concat(subFilename, " from zip archive: ").concat(error));
fileMap[relativePath] = error;
});
promises.push(promise["catch"](function (e) {
return e;
}));
});
return Promise.all(promises);
}).then(function () {
return fileMap;
})["catch"](function (error) {
options.log.error("Unable to read zip archive: ".concat(error));
throw error;
});
function parseZipAsync(_x, _x2) {
return _parseZipAsync.apply(this, arguments);
}
function _parseZipAsync() {
_parseZipAsync = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(data, options) {
var promises, fileMap, jsZip, zip;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
promises = [];
fileMap = {};
_context.prev = 2;
jsZip = new _jszip["default"]();
_context.next = 6;
return jsZip.loadAsync(data, options);
case 6:
zip = _context.sent;
zip.forEach(function (relativePath, zipEntry) {
var subFilename = zipEntry.name;
var promise = loadZipEntry(jsZip, subFilename, options).then(function (arrayBufferOrError) {
fileMap[relativePath] = arrayBufferOrError;
});
promises.push(promise);
});
_context.next = 10;
return Promise.all(promises);
case 10:
return _context.abrupt("return", fileMap);
case 13:
_context.prev = 13;
_context.t0 = _context["catch"](2);
options.log.error("Unable to read zip archive: ".concat(_context.t0));
throw _context.t0;
case 17:
case "end":
return _context.stop();
}
}
}, _callee, null, [[2, 13]]);
}));
return _parseZipAsync.apply(this, arguments);
}
function loadZipEntry(_x3, _x4, _x5) {
return _loadZipEntry.apply(this, arguments);
}
function _loadZipEntry() {
_loadZipEntry = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee2(jsZip, subFilename, options) {
var arrayBuffer;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.prev = 0;
_context2.next = 3;
return jsZip.file(subFilename).async(options.dataType || 'arraybuffer');
case 3:
arrayBuffer = _context2.sent;
return _context2.abrupt("return", arrayBuffer);
case 7:
_context2.prev = 7;
_context2.t0 = _context2["catch"](0);
options.log.error("Unable to read ".concat(subFilename, " from zip archive: ").concat(_context2.t0));
return _context2.abrupt("return", _context2.t0);
case 11:
case "end":
return _context2.stop();
}
}
}, _callee2, null, [[0, 7]]);
}));
return _loadZipEntry.apply(this, arguments);
}
//# sourceMappingURL=zip-loader.js.map

@@ -7,26 +7,37 @@ import JSZip from 'jszip';

category: 'archive',
test: 'PK',
parse: parseZipAsync
};
function parseZipAsync(data, options) {
async function parseZipAsync(data, options) {
const promises = [];
const fileMap = {};
const jsZip = new JSZip();
return jsZip.loadAsync(data, options).then(zip => {
try {
const jsZip = new JSZip();
const zip = await jsZip.loadAsync(data, options);
zip.forEach((relativePath, zipEntry) => {
const subFilename = zipEntry.name;
const promise = jsZip.file(subFilename).async(options.dataType || 'arraybuffer').then(arrayBuffer => {
fileMap[relativePath] = arrayBuffer;
}).catch(error => {
options.log.error("Unable to read ".concat(subFilename, " from zip archive: ").concat(error));
fileMap[relativePath] = error;
const promise = loadZipEntry(jsZip, subFilename, options).then(arrayBufferOrError => {
fileMap[relativePath] = arrayBufferOrError;
});
promises.push(promise.catch(e => e));
promises.push(promise);
});
return Promise.all(promises);
}).then(() => fileMap).catch(error => {
await Promise.all(promises);
return fileMap;
} catch (error) {
options.log.error("Unable to read zip archive: ".concat(error));
throw error;
});
}
}
async function loadZipEntry(jsZip, subFilename, options) {
try {
const arrayBuffer = await jsZip.file(subFilename).async(options.dataType || 'arraybuffer');
return arrayBuffer;
} catch (error) {
options.log.error("Unable to read ".concat(subFilename, " from zip archive: ").concat(error));
return error;
}
}
//# sourceMappingURL=zip-loader.js.map

@@ -0,1 +1,3 @@

import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import JSZip from 'jszip';

@@ -7,30 +9,89 @@ export var ZipLoader = {

category: 'archive',
test: 'PK',
parse: parseZipAsync
};
function parseZipAsync(data, options) {
var promises = [];
var fileMap = {};
var jsZip = new JSZip();
return jsZip.loadAsync(data, options).then(function (zip) {
zip.forEach(function (relativePath, zipEntry) {
var subFilename = zipEntry.name;
var promise = jsZip.file(subFilename).async(options.dataType || 'arraybuffer').then(function (arrayBuffer) {
fileMap[relativePath] = arrayBuffer;
})["catch"](function (error) {
options.log.error("Unable to read ".concat(subFilename, " from zip archive: ").concat(error));
fileMap[relativePath] = error;
});
promises.push(promise["catch"](function (e) {
return e;
}));
});
return Promise.all(promises);
}).then(function () {
return fileMap;
})["catch"](function (error) {
options.log.error("Unable to read zip archive: ".concat(error));
throw error;
});
function parseZipAsync(_x, _x2) {
return _parseZipAsync.apply(this, arguments);
}
function _parseZipAsync() {
_parseZipAsync = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(data, options) {
var promises, fileMap, jsZip, zip;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
promises = [];
fileMap = {};
_context.prev = 2;
jsZip = new JSZip();
_context.next = 6;
return jsZip.loadAsync(data, options);
case 6:
zip = _context.sent;
zip.forEach(function (relativePath, zipEntry) {
var subFilename = zipEntry.name;
var promise = loadZipEntry(jsZip, subFilename, options).then(function (arrayBufferOrError) {
fileMap[relativePath] = arrayBufferOrError;
});
promises.push(promise);
});
_context.next = 10;
return Promise.all(promises);
case 10:
return _context.abrupt("return", fileMap);
case 13:
_context.prev = 13;
_context.t0 = _context["catch"](2);
options.log.error("Unable to read zip archive: ".concat(_context.t0));
throw _context.t0;
case 17:
case "end":
return _context.stop();
}
}
}, _callee, null, [[2, 13]]);
}));
return _parseZipAsync.apply(this, arguments);
}
function loadZipEntry(_x3, _x4, _x5) {
return _loadZipEntry.apply(this, arguments);
}
function _loadZipEntry() {
_loadZipEntry = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(jsZip, subFilename, options) {
var arrayBuffer;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.prev = 0;
_context2.next = 3;
return jsZip.file(subFilename).async(options.dataType || 'arraybuffer');
case 3:
arrayBuffer = _context2.sent;
return _context2.abrupt("return", arrayBuffer);
case 7:
_context2.prev = 7;
_context2.t0 = _context2["catch"](0);
options.log.error("Unable to read ".concat(subFilename, " from zip archive: ").concat(_context2.t0));
return _context2.abrupt("return", _context2.t0);
case 11:
case "end":
return _context2.stop();
}
}
}, _callee2, null, [[0, 7]]);
}));
return _loadZipEntry.apply(this, arguments);
}
//# sourceMappingURL=zip-loader.js.map
{
"name": "@loaders.gl/zip",
"version": "1.3.3",
"version": "2.0.0-alpha.1",
"description": "Zip Archive Loader",

@@ -33,6 +33,6 @@ "license": "MIT",

"dependencies": {
"@loaders.gl/core": "1.3.3",
"@loaders.gl/core": "2.0.0-alpha.1",
"jszip": "^3.1.5"
},
"gitHead": "6a8d559e11613dc1dd94a12e4ea5df05c0184ae6"
"gitHead": "cff57d05c0495fa661119005cffd886ed6ed1025"
}

@@ -8,2 +8,3 @@ import JSZip from 'jszip';

category: 'archive',
test: 'PK',
parse: parseZipAsync

@@ -13,43 +14,42 @@ };

// TODO - Could return a map of promises, perhaps as an option...
function parseZipAsync(data, options) {
async function parseZipAsync(data, options) {
const promises = [];
const fileMap = {};
const jsZip = new JSZip();
return (
jsZip
.loadAsync(data, options)
.then(zip => {
// start to load each file in this zip
zip.forEach((relativePath, zipEntry) => {
const subFilename = zipEntry.name;
try {
const jsZip = new JSZip();
const promise = jsZip
.file(subFilename)
// jszip supports both arraybuffer and text, the main loaders.gl types
// https://stuk.github.io/jszip/documentation/api_zipobject/async.html
.async(options.dataType || 'arraybuffer')
.then(arrayBuffer => {
// Store file data in map
fileMap[relativePath] = arrayBuffer;
})
.catch(error => {
options.log.error(`Unable to read ${subFilename} from zip archive: ${error}`);
// Store error in place of data in map
fileMap[relativePath] = error;
});
const zip = await jsZip.loadAsync(data, options);
// Ensure Promise.all doesn't ignore rejected promises.
promises.push(promise.catch(e => e));
});
// start to load each file in this zip
zip.forEach((relativePath, zipEntry) => {
const subFilename = zipEntry.name;
return Promise.all(promises);
})
// Return fileMap
.then(() => fileMap)
.catch(error => {
options.log.error(`Unable to read zip archive: ${error}`);
throw error;
})
);
const promise = loadZipEntry(jsZip, subFilename, options).then(arrayBufferOrError => {
fileMap[relativePath] = arrayBufferOrError;
});
// Ensure Promise.all doesn't ignore rejected promises.
promises.push(promise);
});
await Promise.all(promises);
return fileMap;
} catch (error) {
options.log.error(`Unable to read zip archive: ${error}`);
throw error;
}
}
async function loadZipEntry(jsZip, subFilename, options) {
// jszip supports both arraybuffer and text, the main loaders.gl types
// https://stuk.github.io/jszip/documentation/api_zipobject/async.html
try {
const arrayBuffer = await jsZip.file(subFilename).async(options.dataType || 'arraybuffer');
return arrayBuffer;
} catch (error) {
options.log.error(`Unable to read ${subFilename} from zip archive: ${error}`);
// Store error in place of data in map
return error;
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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