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

unzipit

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unzipit - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

32

dist/unzipit.js

@@ -1,2 +0,2 @@

/* unzipit@0.0.3, license MIT */
/* unzipit@0.0.4, license MIT */
(function (global, factory) {

@@ -701,15 +701,15 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :

/*
const decodeCP437 = (function() {
const cp437 = '\u0000☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ';
/* eslint-disable no-irregular-whitespace */
// const decodeCP437 = (function() {
// const cp437 = '\u0000☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ';
//
// return function(uint8view) {
// return Array.from(uint8view).map(v => cp437[v]).join('');
// };
// }());
/* eslint-enable no-irregular-whitespace */
return function(uint8view) {
return Array.from(uint8view).map(v => cp437[v]).join('');
};
}());
*/
const utf8Decoder = new TextDecoder();
function decodeBuffer(uint8View, isUTF8) {
return utf8Decoder.decode(uint8View);
function decodeBuffer(uint8View/*, isUTF8*/) {
return utf8Decoder.decode(uint8View);
/*

@@ -945,5 +945,5 @@ AFAICT the UTF8 flat is not set so it's 100% up to the user

// validate file size
if (self.validateEntrySizes && entry.compressionMethod === 0) {
if (entry.compressionMethod === 0) {
let expectedCompressedSize = entry.uncompressedSize;
if (entry.isEncrypted()) {
if ((entry.generalPurposeBitFlag & 0x1) !== 0) {
// traditional encryption prefixes the file data with a header

@@ -1029,3 +1029,3 @@ expectedCompressedSize += 12;

let reader;
if (source instanceof Blob) {
if (typeof Blob !== 'undefined' && source instanceof Blob) {
reader = new BlobReader(source);

@@ -1038,3 +1038,3 @@ } else if (source instanceof ArrayBuffer || (source && source.buffer && source.buffer instanceof ArrayBuffer)) {

reader = new BlobReader(blob);
} else if (typeof source.length === 'number' && typeof source.read === 'function') {
} else if (typeof source.getLength === 'function' && typeof source.read === 'function') {
reader = source;

@@ -1041,0 +1041,0 @@ } else {

@@ -1,2 +0,2 @@

/* unzipit@0.0.3, license MIT */
/* unzipit@0.0.4, license MIT */
class ArrayBufferReader {

@@ -695,15 +695,15 @@ constructor(arrayBufferOrView) {

/*
const decodeCP437 = (function() {
const cp437 = '\u0000☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ';
/* eslint-disable no-irregular-whitespace */
// const decodeCP437 = (function() {
// const cp437 = '\u0000☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ';
//
// return function(uint8view) {
// return Array.from(uint8view).map(v => cp437[v]).join('');
// };
// }());
/* eslint-enable no-irregular-whitespace */
return function(uint8view) {
return Array.from(uint8view).map(v => cp437[v]).join('');
};
}());
*/
const utf8Decoder = new TextDecoder();
function decodeBuffer(uint8View, isUTF8) {
return utf8Decoder.decode(uint8View);
function decodeBuffer(uint8View/*, isUTF8*/) {
return utf8Decoder.decode(uint8View);
/*

@@ -939,5 +939,5 @@ AFAICT the UTF8 flat is not set so it's 100% up to the user

// validate file size
if (self.validateEntrySizes && entry.compressionMethod === 0) {
if (entry.compressionMethod === 0) {
let expectedCompressedSize = entry.uncompressedSize;
if (entry.isEncrypted()) {
if ((entry.generalPurposeBitFlag & 0x1) !== 0) {
// traditional encryption prefixes the file data with a header

@@ -1023,3 +1023,3 @@ expectedCompressedSize += 12;

let reader;
if (source instanceof Blob) {
if (typeof Blob !== 'undefined' && source instanceof Blob) {
reader = new BlobReader(source);

@@ -1032,3 +1032,3 @@ } else if (source instanceof ArrayBuffer || (source && source.buffer && source.buffer instanceof ArrayBuffer)) {

reader = new BlobReader(blob);
} else if (typeof source.length === 'number' && typeof source.read === 'function') {
} else if (typeof source.getLength === 'function' && typeof source.read === 'function') {
reader = source;

@@ -1035,0 +1035,0 @@ } else {

{
"name": "unzipit",
"version": "0.0.3",
"version": "0.0.4",
"description": "random access unzip library for JavaScript",

@@ -9,3 +9,4 @@ "main": "dist/unzipit.js",

"build": "rollup -c",
"test": "node test/puppeteer.notjs"
"eslint": "eslint src/**/*.js test/tests/**/*.js",
"test": "mocha test/node-test.js && node test/puppeteer.notjs"
},

@@ -12,0 +13,0 @@ "files": [

# unzipit.js
Random access unzip library for browser based JavaScript
Random access unzip library for browser and node based JavaScript
## How to use
### Browser
```js

@@ -28,2 +30,98 @@ import unzipit from 'unzipit';

### Node
I'm not quite sure if I should expose node readers or let you do your
own but here's 3 examples
#### Load a file as an arraybuffer
```js
const unzipit = require('unzipit');
const fsPromises = require('fs').promises;
async function readFiles(filename) {
const buf = await fsPromises.readFile(filename);
const {zip, entries} = await unzipit(new Uint8Array(buf));
... (see code above)
}
```
You can also pass your own reader. Here's 2 examples. This first one
is stateless. That means there is never anything to clean up. But,
it has the overhead of opening the source file once for each time
you get the contents of an entry. I have no idea what the overhead
of that is.
```js
const unzipit = require('unzipit');
const fsPromises = require('fs').promises;
class StatelessFileReader {
constructor(filename) {
this.filename = filename;
}
async getLength() {
if (this.length === undefined) {
const stat = await fsPromises.stat(this.filename);
this.length = stat.size;
}
return this.length;
}
async read(offset, length) {
const fh = await fsPromises.open(this.filename);
const data = new Uint8Array(length);
await fh.read(data, 0, length, offset);
await fh.close();
return data;
}
}
async function readFiles(filename) {
const reader = new StatelessFileReader(filename);
const {zip, entries} = await unzipit(reader);
... (see code above)
}
```
Here's also an example of one that only opens the file a single time
but that means the file stays open until you manually call close.
```js
class FileReader {
constructor(filename) {
this.fhp = fsPromises.open(filename);
}
async close() {
const fh = await this.fhp;
await fh.close();
}
async getLength() {
if (this.length === undefined) {
const fh = await this.fhp;
const stat = await fh.stat();
this.length = stat.size;
}
return this.length;
}
async read(offset, length) {
const fh = await this.fhp;
const data = new Uint8Array(length);
await fh.read(data, 0, length, offset);
return data;
}
}
async function doStuff() {
// ...
const reader = new FileReader(filename);
const {zip, entries} = await unzipit(reader);
// ... do stuff with entries ...
// you must call reader.close for the file to close
await reader.close();
}
```
## Why?

@@ -159,2 +257,3 @@

}
return this.length;
}

@@ -161,0 +260,0 @@ async read(offset, size) {

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