Socket
Socket
Sign inDemoInstall

then-read-stream

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

then-read-stream - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

39

lib/index.js

@@ -29,12 +29,30 @@ "use strict";

StreamReader.prototype.read = function (buffer, offset, length, position) {
var _this = this;
if (position === void 0) { position = null; }
this.request = {
buffer: buffer,
offset: offset,
length: length,
position: position,
deferred: new Deferred()
};
this.tryRead();
return this.request.deferred.promise;
if (this.request)
throw new Error("Concurrent read operation");
var readBuffer = this.s.read(length);
if (readBuffer) {
readBuffer.copy(buffer, offset);
return es6_promise_1.Promise.resolve(length);
}
else {
this.request = {
buffer: buffer,
offset: offset,
length: length,
position: position,
deferred: new Deferred()
};
this.s.once("readable", function () {
_this.tryRead();
});
return this.request.deferred.promise.then(function (n) {
_this.request = null;
return n;
})["catch"](function (err) {
_this.request = null;
throw err;
});
}
};

@@ -47,5 +65,2 @@ StreamReader.prototype.tryRead = function () {

this.request.deferred.resolve(this.request.length);
process.nextTick(function () {
_this.request = null;
});
}

@@ -52,0 +67,0 @@ else {

{
"name": "then-read-stream",
"version": "0.0.5",
"version": "0.0.6",
"description": "Read from a readable stream just like a file",

@@ -5,0 +5,0 @@ "author": {

@@ -54,11 +54,29 @@ import {Promise} from "es6-promise";

this.request = {
buffer,
offset,
length,
position,
deferred: new Deferred<number>()
};
this.tryRead();
return this.request.deferred.promise;
if (this.request)
throw new Error("Concurrent read operation");
const readBuffer = this.s.read(length);
if (readBuffer) {
readBuffer.copy(buffer, offset);
return Promise.resolve<number>(length);
} else {
this.request = {
buffer,
offset,
length,
position,
deferred: new Deferred<number>()
};
this.s.once("readable", () => {
this.tryRead();
});
return this.request.deferred.promise.then((n) => {
this.request = null;
return n;
}).catch( (err) => {
this.request = null;
throw err;
});
}
}

@@ -71,5 +89,2 @@

this.request.deferred.resolve(this.request.length);
process.nextTick(() => {
this.request = null;
});
} else {

@@ -76,0 +91,0 @@ this.s.once("readable", () => {

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