@@ -259,7 +259,9 @@ File.prototype.createReadStream = function(options) {
259
259
options = options || { } ;
260
260
261
261
var that = this ;
262
- var throughStream = through ( ) ;
262
+ var rangeRequest =
263
+ util . is ( options . start , 'number' ) || util . is ( options . end , 'number' ) ;
264
+ var throughStream = streamEvents ( through ( ) ) ;
263
265
264
266
var validations = [ 'crc32c' , 'md5' ] ;
265
267
var validation ;
@@ -278,6 +280,10 @@ File.prototype.createReadStream = function(options) {
278
280
validation = 'all' ;
279
281
}
280
282
283
+ if ( rangeRequest ) {
284
+ validation = false ;
285
+ }
286
+
281
287
var crc32c = validation === 'crc32c' || validation === 'all' ;
282
288
var md5 = validation === 'md5' || validation === 'all' ;
283
289
@@ -304,7 +310,7 @@ File.prototype.createReadStream = function(options) {
304
310
uri : uri
305
311
} ;
306
312
307
- if ( util . is ( options . start , 'number' ) || util . is ( options . end , 'number' ) ) {
313
+ if ( rangeRequest ) {
308
314
reqOpts . headers = {
309
315
Range : 'bytes=' + [ options . start || '' , options . end || '' ] . join ( '-' )
310
316
} ;
@@ -340,6 +346,13 @@ File.prototype.createReadStream = function(options) {
340
346
} )
341
347
342
348
. on ( 'complete' , function ( res ) {
349
+ if ( rangeRequest ) {
350
+ // Range requests can't receive data integrity checks.
351
+ throughStream . emit ( 'complete' , res ) ;
352
+ throughStream . end ( ) ;
353
+ return ;
354
+ }
355
+
343
356
var failed = false ;
344
357
var crcFail = true ;
345
358
var md5Fail = true ;
@@ -378,7 +391,7 @@ File.prototype.createReadStream = function(options) {
378
391
379
392
throughStream . emit ( 'error' , error ) ;
380
393
} else {
381
- throughStream . emit ( 'complete' ) ;
394
+ throughStream . emit ( 'complete' , res ) ;
382
395
}
383
396
384
397
throughStream . end ( ) ;
0 commit comments