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

fd-slicer

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fd-slicer - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

4

CHANGELOG.md

@@ -0,1 +1,5 @@

### 0.3.2
* fix write stream and read stream destroy behavior
### 0.3.1

@@ -2,0 +6,0 @@

18

index.js

@@ -98,2 +98,3 @@ var fs = require('fs');

if (toRead <= 0) {
self.destroyed = true;
self.push(null);

@@ -108,5 +109,5 @@ self.context.unref();

if (err) {
self.destroy();
self.emit('error', err);
self.destroy(err);
} else if (bytesRead === 0) {
self.destroyed = true;
self.push(null);

@@ -123,4 +124,8 @@ self.context.unref();

ReadStream.prototype.destroy = function() {
ReadStream.prototype.destroy = function(err) {
if (this.destroyed) return;
err = err || new Error("stream destroyed");
this.destroyed = true;
this.emit('error', err);
this.context.unref();
};

@@ -142,5 +147,3 @@

this.on('finish', function() {
context.unref();
});
this.on('finish', this.destroy.bind(this));
}

@@ -155,2 +158,3 @@

err.code = 'ETOOBIG';
self.destroy();
callback(err);

@@ -178,3 +182,5 @@ return;

WriteStream.prototype.destroy = function() {
if (this.destroyed) return;
this.destroyed = true;
this.context.unref();
};
{
"name": "fd-slicer",
"version": "0.3.1",
"version": "0.3.2",
"description": "safely create multiple ReadStream or WriteStream objects from the same file descriptor",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -106,3 +106,5 @@ # fd-slicer

* `destroy()` - stop streaming
* `destroy(err)` - stop streaming. `err` is optional and is the error that
will be emitted in order to cause the streaming to stop. Defaults to
`new Error("stream destroyed")`.

@@ -109,0 +111,0 @@ ##### createWriteStream(options)

@@ -174,7 +174,7 @@ var FdSlicer = require('../');

if (err) return done(err);
var fdSlicer = new FdSlicer(fd);
var fdSlicer = new FdSlicer(fd, {autoClose: true});
var ws = fdSlicer.createWriteStream({start: 0, end: 1000});
ws.on('error', function(err) {
assert.strictEqual(err.code, 'ETOOBIG');
done();
fdSlicer.on('close', done);
});

@@ -202,3 +202,3 @@ ws.end(new Buffer(1001));

assert.strictEqual(err.code, 'ETOOBIG');
done();
fdSlicer.on('close', done);
});

@@ -231,2 +231,26 @@ ws.end(new Buffer(1000));

});
it("write stream unrefs when destroyed", function(done) {
fs.open(testOutBlobFile, 'w', function(err, fd) {
if (err) return done(err);
var fdSlicer = new FdSlicer(fd, {autoClose: true});
var ws = fdSlicer.createWriteStream();
fdSlicer.on('close', done);
ws.write(new Buffer(1000));
ws.destroy();
});
});
it("read stream unrefs when destroyed", function(done) {
fs.open(testBlobFile, 'r', function(err, fd) {
if (err) return done(err);
var fdSlicer = new FdSlicer(fd, {autoClose: true});
var rs = fdSlicer.createReadStream();
rs.on('error', function(err) {
assert.strictEqual(err.message, "stream destroyed");
fdSlicer.on('close', done);
});
rs.destroy();
});
});
});
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