Skip to content

Commit

Permalink
Breaking: Replace flush-write-stream with streamx module
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Apr 28, 2020
1 parent d93637d commit 4cb4270
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
12 changes: 2 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var Writable = require('flush-write-stream');
var Writable = require('streamx').Writable;

function listenerCount(stream, evt) {
return stream.listeners(evt).length;
Expand All @@ -10,18 +10,10 @@ function hasListeners(stream) {
return !!(listenerCount(stream, 'readable') || listenerCount(stream, 'data'));
}

function sinker(file, enc, callback) {
callback();
}

function sink(stream) {
var sinkAdded = false;

var sinkOptions = {
objectMode: stream._readableState.objectMode,
};

var sinkStream = new Writable(sinkOptions, sinker);
var sinkStream = new Writable();

function addSink() {
if (sinkAdded) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"test": "nyc mocha --async-only"
},
"dependencies": {
"flush-write-stream": "^2.0.0"
"streamx": "^2.6.0"
},
"devDependencies": {
"eslint": "^6.8.0",
Expand Down
44 changes: 42 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,47 @@ function slowCount(value) {
}

describe('lead', function () {
it('respects objectMode of wrapped stream', function (done) {
it('can wrap binary stream', function (done) {
var write = sink(through());

function assert(err) {
// Forced an object through a non-object stream
expect(err).toBeFalsy();
done();
}

pipe(
[
from(['1', '2', '3']),
// Must be in the Writable position to test this
// So concat-stream cannot be used
write,
],
assert
);
});

it('can wrap object stream', function (done) {
var write = sink(through.obj());

function assert(err) {
// Forced an object through a non-object stream
expect(err).toBeFalsy();
done();
}

pipe(
[
from.obj([{}, {}, {}]),
// Must be in the Writable position to test this
// So concat-stream cannot be used
write,
],
assert
);
});

it('does not convert between object and binary stream', function (done) {
var write = sink(through());

function assert(err) {
Expand All @@ -55,7 +95,7 @@ describe('lead', function () {

pipe(
[
from.obj([{}]),
from.obj([{}, {}, {}]),
// Must be in the Writable position to test this
// So concat-stream cannot be used
write,
Expand Down

0 comments on commit 4cb4270

Please sign in to comment.