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

@saulx/utils

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@saulx/utils - npm Package Compare versions

Comparing version 4.2.1 to 4.3.0

5

dist/src/readStream.d.ts
/// <reference types="node" resolution-mode="require"/>
import { Stream } from 'stream';
export declare const readStream: (stream: Stream) => Promise<Buffer>;
export declare const readStream: (stream: Stream, opts?: {
throttle?: number;
maxCunkSize?: number;
}) => Promise<Buffer>;

@@ -1,22 +0,61 @@

import { PassThrough } from 'stream';
export const readStream = (stream) => new Promise((resolve, reject) => {
const s = new PassThrough();
s.on('error', (err) => {
reject(err);
});
let buffers = [];
s.on('data', (s) => {
if (typeof s === 'string') {
buffers.push(Buffer.from(s));
import { Writable } from 'stream';
export const readStream = (stream, opts) => new Promise((resolve, reject) => {
const maxCunkSize = opts?.maxCunkSize ?? 0;
const throttle = opts?.throttle ?? 0;
const buffers = [];
const processChunk = (c, next) => {
buffers.push(c.slice(0, maxCunkSize));
const chunkP = c.slice(maxCunkSize);
if (chunkP.byteLength > maxCunkSize) {
if (throttle) {
setTimeout(() => {
processChunk(chunkP, next);
}, throttle);
}
else {
processChunk(chunkP, next);
}
}
else {
buffers.push(s);
if (throttle) {
setTimeout(() => {
next();
}, throttle);
}
else {
next();
}
}
};
const s = new Writable({
write: (c, _encoding, next) => {
if (maxCunkSize && c.byteLength > maxCunkSize) {
processChunk(c, next);
}
else {
if (typeof c === 'string') {
buffers.push(Buffer.from(c));
}
else {
buffers.push(c);
}
if (throttle) {
setTimeout(() => {
next();
}, throttle);
}
else {
next();
}
}
},
});
s.on('end', () => {
s.on('error', (err) => {
reject(err);
});
s.on('finish', () => {
resolve(Buffer.concat(buffers));
});
// @ts-ignore
stream.pipe(s);
});
//# sourceMappingURL=readStream.js.map

2

package.json
{
"name": "@saulx/utils",
"version": "4.2.1",
"version": "4.3.0",
"repository": "https://github.com/atelier-saulx/utils",

@@ -5,0 +5,0 @@ "files": [

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