File tree 2 files changed +20
-2
lines changed
2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -28,8 +28,15 @@ jBinary.loadData = promising(function (source, callback) {
28
28
if ( NODE && is ( source , ReadableStream ) ) {
29
29
var buffers = [ ] ;
30
30
source
31
- . on ( 'readable' , function ( ) { buffers . push ( this . read ( ) ) } )
32
- . on ( 'end' , function ( ) { callback ( null , Buffer . concat ( buffers ) ) } )
31
+ . on ( 'readable' , function ( ) {
32
+ var buf = this . read ( ) ;
33
+ if ( buf ) {
34
+ buffers . push ( buf ) ;
35
+ }
36
+ } )
37
+ . on ( 'end' , function ( ) {
38
+ callback ( null , Buffer . concat ( buffers ) ) ;
39
+ } )
33
40
. on ( 'error' , callback )
34
41
;
35
42
} else
Original file line number Diff line number Diff line change @@ -204,6 +204,17 @@ suite('Loading data', function () {
204
204
} ) ;
205
205
}
206
206
207
+ if ( hasNodeRequire && require ( 'stream' ) . Readable ) {
208
+ test ( 'from file-based readableStream' , function ( done ) {
209
+ var stream = require ( 'fs' ) . createReadStream ( localFileName ) ;
210
+ jBinary . loadData ( stream , function ( err , data ) {
211
+ assert . notOk ( err , err ) ;
212
+ assert . equal ( data . byteLength || data . length , 512 ) ;
213
+ done ( ) ;
214
+ } ) ;
215
+ } ) ;
216
+ }
217
+
207
218
test ( 'with explicit typeset object' , function ( done ) {
208
219
var typeSet = {
209
220
IS_CORRECT_TYPESET : true
You can’t perform that action at this time.
0 commit comments