Socket
Socket
Sign inDemoInstall

peek-readable

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

peek-readable - npm Package Compare versions

Comparing version 4.0.2 to 4.1.0

12

lib/StreamReader.d.ts

@@ -7,5 +7,5 @@ /// <reference types="node" />

/**
* Deferred read request
* Deferred used for postponed read request (as not data is yet available to read)
*/
private request;
private deferred;
private endOfStream;

@@ -41,5 +41,9 @@ /**

*/
private _read;
private tryRead;
private readFromStream;
/**
* Process deferred read request
* @param request Deferred read request
*/
private readDeferred;
private reject;
}

@@ -13,5 +13,5 @@ "use strict";

/**
* Deferred read request
* Deferred used for postponed read request (as not data is yet available to read)
*/
this.request = null;
this.deferred = null;
this.endOfStream = false;

@@ -75,3 +75,3 @@ /**

const reqLen = Math.min(remaining, maxStreamReadSize);
const chunkLen = await this._read(buffer, offset + bytesRead, reqLen);
const chunkLen = await this.readFromStream(buffer, offset + bytesRead, reqLen);
bytesRead += chunkLen;

@@ -91,5 +91,3 @@ if (chunkLen < reqLen)

*/
async _read(buffer, offset, length) {
if (this.request)
throw new Error('Concurrent read operation?');
async readFromStream(buffer, offset, length) {
const readBuffer = this.s.read(length);

@@ -101,3 +99,3 @@ if (readBuffer) {

else {
this.request = {
const request = {
buffer,

@@ -108,20 +106,23 @@ offset,

};
this.deferred = request.deferred;
this.s.once('readable', () => {
this.tryRead();
this.readDeferred(request);
});
return this.request.deferred.promise;
return request.deferred.promise;
}
}
tryRead() {
if (!this.request)
throw new Error('this.request should be defined');
const readBuffer = this.s.read(this.request.length);
/**
* Process deferred read request
* @param request Deferred read request
*/
readDeferred(request) {
const readBuffer = this.s.read(request.length);
if (readBuffer) {
this.request.buffer.set(readBuffer, this.request.offset);
this.request.deferred.resolve(readBuffer.length);
this.request = null;
request.buffer.set(readBuffer, request.offset);
request.deferred.resolve(readBuffer.length);
this.deferred = null;
}
else {
this.s.once('readable', () => {
this.tryRead();
this.readDeferred(request);
});

@@ -132,5 +133,5 @@ }

this.endOfStream = true;
if (this.request) {
this.request.deferred.reject(err);
this.request = null;
if (this.deferred) {
this.deferred.reject(err);
this.deferred = null;
}

@@ -137,0 +138,0 @@ }

{
"name": "peek-readable",
"version": "4.0.2",
"version": "4.1.0",
"description": "Read and peek from a readable stream",

@@ -46,17 +46,23 @@ "author": {

"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^4.31.0",
"@typescript-eslint/parser": "^4.31.0",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"add": "^2.0.6",
"chai": "^4.3.4",
"chai": "^4.3.6",
"coveralls": "^3.1.1",
"del-cli": "^4.0.1",
"eslint": "^7.32.0",
"mocha": "^9.1.3",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsdoc": "^37.7.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-unicorn": "^40.1.0",
"mocha": "^9.2.0",
"nyc": "^15.1.0",
"remark-cli": "^10.0.0",
"remark-cli": "^10.0.1",
"remark-preset-lint-recommended": "^6.1.2",
"ts-node": "^10.1.0",
"typescript": "^4.4.2"
"ts-node": "^10.4.0",
"typescript": "^4.5.5"
},

@@ -63,0 +69,0 @@ "keywords": [

@@ -30,3 +30,3 @@ ![Node.js CI](https://github.com/Borewit/peek-readable/workflows/Node.js%20CI/badge.svg)

NPM module is compliant with [ECMAScript 2017 (ES8)](https://en.wikipedia.org/wiki/ECMAScript#8th_Edition_-_ECMAScript_2017).
NPM module is compliant with [ECMAScript 2018 (ES9)](https://en.wikipedia.org/wiki/ECMAScript#9th_Edition_%E2%80%93_ECMAScript_2018).

@@ -33,0 +33,0 @@ ## Examples

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