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

unpack-stream

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unpack-stream - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

5

dist/index.d.ts

@@ -8,2 +8,3 @@ /// <reference types="node" />

shasum?: string;
generateIntegrity?: boolean;
};

@@ -28,2 +29,4 @@ export declare function remote(stream: IncomingMessage, dest: string, opts: UnpackRemoteStreamOptions): Promise<{}>;

};
export declare function local(stream: NodeJS.ReadableStream, dest: string): Promise<{}>;
export declare function local(stream: NodeJS.ReadableStream, dest: string, opts?: {
generateIntegrity?: boolean;
}): Promise<{}>;

69

dist/index.js

@@ -11,4 +11,17 @@ "use strict";

const actualShasum = crypto.createHash('sha1');
if (stream.statusCode !== 200) {
return reject(new Error(`Invalid response: ${stream.statusCode}`));
}
if (opts.onStart)
opts.onStart();
if (opts.onProgress && stream.headers['content-length']) {
const onProgress = opts.onProgress;
let downloaded = 0;
let size = parseInt(stream.headers['content-length']);
stream.on('data', (chunk) => {
downloaded += chunk.length;
onProgress(downloaded, size);
});
}
local(stream
.on('response', start)
.on('data', (_) => { actualShasum.update(_); })

@@ -19,18 +32,2 @@ .on('error', reject), dest).then(finish).catch(reject);

stream.resume();
function start(res) {
if (res.statusCode !== 200) {
return reject(new Error(`Invalid response: ${res.statusCode}`));
}
if (opts.onStart)
opts.onStart();
if (opts.onProgress && ('content-length' in res.headers)) {
const onProgress = opts.onProgress;
let downloaded = 0;
let size = +res.headers['content-length'];
res.on('data', (chunk) => {
downloaded += chunk.length;
onProgress(downloaded, size);
});
}
}
function finish(index) {

@@ -47,3 +44,5 @@ const digest = actualShasum.digest('hex');

exports.remote = remote;
function local(stream, dest) {
function local(stream, dest, opts) {
opts = opts || {};
const generateIntegrity = opts.generateIntegrity !== false;
const index = {};

@@ -60,11 +59,13 @@ const headers = {};

headers[header.name] = header;
integrityPromises.push(ssri.fromStream(fileStream)
.then((sri) => {
index[header.name] = {
integrity: sri.toString(),
type: header['type'],
size: header['size'],
mtime: header['mtime'],
};
}));
if (generateIntegrity) {
integrityPromises.push(ssri.fromStream(fileStream)
.then((sri) => {
index[header.name] = {
integrity: sri.toString(),
type: header['type'],
size: header['size'],
mtime: header['mtime'],
};
}));
}
return fileStream;

@@ -74,7 +75,11 @@ },

.on('finish', () => {
resolve({
headers,
integrityPromise: Promise.all(integrityPromises)
.then(() => index)
});
if (generateIntegrity) {
resolve({
headers,
integrityPromise: Promise.all(integrityPromises)
.then(() => index)
});
return;
}
resolve({ headers });
});

@@ -81,0 +86,0 @@ });

{
"name": "unpack-stream",
"version": "2.0.0",
"version": "2.1.0",
"description": "Unpack a tarball stream",

@@ -37,3 +37,3 @@ "main": "dist/index.js",

"dependencies": {
"@types/node": "^7.0.0",
"@types/node": "^8.0.14",
"decompress-maybe": "^1.0.0",

@@ -49,5 +49,5 @@ "ssri": "^4.1.6",

"rimraf": "^2.6.1",
"tape": "^4.6.3",
"tape": "^4.7.0",
"ts-node": "^3.0.6",
"typescript": "^2.0.3"
"typescript": "^2.4.2"
},

@@ -54,0 +54,0 @@ "mos": {

@@ -63,9 +63,14 @@ # unpack-stream

- `[opts.onProgress]` - _(downloaded, size) => void_ - tracks the download progress
- `[opts.generateIntegrity]` - _Boolean_ - `true` by default. If `true`, generates [Subresource Integrity](https://w3c.github.io/webappsec-subresource-integrity/) for each unpacked file
### `local(stream, destination): Promise<Index>`
### `local(stream, destination, [opts]): Promise<Index>`
Unpacks a stream from the local filesystem.
**Arguments:**
- `[opts.generateIntegrity]` - _Boolean_ - `true` by default. If `true`, generates [Subresource Integrity](https://w3c.github.io/webappsec-subresource-integrity/) for each unpacked file
## License
[MIT](./LICENSE) © [Zoltan Kochan](http://kochan.io)

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