Comparing version 0.1.3 to 0.1.7
@@ -15,6 +15,6 @@ | ||
if(Array.isArray(source)) { | ||
source = source.slice() | ||
var source_index = 0, source_len = source.length; | ||
return from (function (i) { | ||
if(source.length) | ||
this.emit('data', source.shift()) | ||
if(source_index < source_len) | ||
this.emit('data', source[source_index++]) | ||
else | ||
@@ -41,3 +41,3 @@ this.emit('end') | ||
if(!s.ended && !s.paused) | ||
next() | ||
process.nextTick(next); | ||
})) | ||
@@ -44,0 +44,0 @@ ; |
{ | ||
"name": "from", | ||
"version": "0.1.3", | ||
"version": "0.1.7", | ||
"description": "Easy way to make a Readable Stream", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -45,2 +45,70 @@ var from = require('..') | ||
exports['inc - async'] = function (test) { | ||
var fs = from(function (i, next) { | ||
this.emit('data', i) | ||
if(i >= 99) | ||
return this.emit('end') | ||
next(); | ||
}) | ||
spec(fs).readable().validateOnExit() | ||
read(fs, function (err, arr) { | ||
test.equal(arr.length, 100) | ||
test.done() | ||
}) | ||
} | ||
exports['large stream - from an array'] = function (test) { | ||
var l = 100000 | ||
, expected = [] | ||
while(l--) expected.push(l * Math.random()) | ||
var fs = from(expected.slice()) | ||
spec(fs).readable().validateOnExit() | ||
read(fs, function (err, arr) { | ||
a.deepEqual(arr, expected) | ||
test.done() | ||
}) | ||
} | ||
exports['large stream - callback return true'] = function (test) { | ||
var fs = from(function (i, next) { | ||
this.emit('data', i) | ||
if(i >= 99999) | ||
return this.emit('end') | ||
return true; | ||
}) | ||
spec(fs).readable().validateOnExit() | ||
read(fs, function (err, arr) { | ||
test.equal(arr.length, 100000) | ||
test.done() | ||
}) | ||
} | ||
exports['large stream - callback call next()'] = function (test) { | ||
var fs = from(function (i, next) { | ||
this.emit('data', i) | ||
if(i >= 99999) | ||
return this.emit('end') | ||
next(); | ||
}) | ||
spec(fs).readable().validateOnExit() | ||
read(fs, function (err, arr) { | ||
test.equal(arr.length, 100000) | ||
test.done() | ||
}) | ||
} | ||
exports['simple'] = function (test) { | ||
@@ -106,3 +174,4 @@ | ||
else | ||
self.emit('end') | ||
if(!self.ended) | ||
self.emit('end') | ||
n() | ||
@@ -109,0 +178,0 @@ }, 3) |
Sorry, the diff of this file is not supported yet
8492
8
223
41