@@ -1002,57 +1002,42 @@ describe('GridFS Stream', function () {
1002
1002
} ) ;
1003
1003
} ) ;
1004
1004
1005
- /**
1006
- * Provide start and end parameters for file download to skip ahead x bytes and limit the total amount of bytes read to n
1007
- *
1008
- * @example -class GridFSBucket
1009
- * @example -method openDownloadStream
1010
- */
1011
- it ( 'NODE-829 start/end options for openDownloadStream where start-end is < size of chunk' , {
1005
+ it ( 'should return only end - start bytes when the end is within a chunk' , {
1012
1006
metadata : { requires : { topology : [ 'single' ] } } ,
1013
-
1014
1007
test ( done ) {
1015
- const configuration = this . configuration ;
1016
- const client = configuration . newClient ( configuration . writeConcernMax ( ) , { maxPoolSize : 1 } ) ;
1017
- client . connect ( function ( err , client ) {
1018
- const db = client . db ( configuration . db ) ;
1019
- const bucket = new GridFSBucket ( db , {
1020
- bucketName : 'gridfsdownload' ,
1021
- chunkSizeBytes : 20
1022
- } ) ;
1008
+ // Provide start and end parameters for file download to skip
1009
+ // ahead x bytes and limit the total amount of bytes read to n
1010
+ const db = client . db ( ) ;
1023
1011
1024
- const readStream = fs . createReadStream ( './LICENSE.md' ) ;
1025
- const uploadStream = bucket . openUploadStream ( 'teststart.dat' ) ;
1012
+ const start = 1 ;
1013
+ const end = 6 ;
1026
1014
1027
- uploadStream . once ( 'finish' , function ( ) {
1028
- const downloadStream = bucket
1029
- . openDownloadStreamByName ( 'teststart.dat' , { start : 1 } )
1030
- . end ( 6 ) ;
1015
+ const bucket = new GridFSBucket ( db , {
1016
+ bucketName : 'gridfsdownload' ,
1017
+ chunkSizeBytes : 20
1018
+ } ) ;
1031
1019
1032
- downloadStream . on ( 'error' , function ( error ) {
1033
- expect ( error ) . to . not . exist ;
1034
- } ) ;
1020
+ const readStream = fs . createReadStream ( './LICENSE.md' ) ;
1021
+ const uploadStream = bucket . openUploadStream ( 'teststart.dat' ) ;
1035
1022
1036
- let gotData = 0 ;
1037
- let str = '' ;
1038
- downloadStream . on ( 'data' , function ( data ) {
1039
- ++ gotData ;
1040
- str += data . toString ( 'utf8' ) ;
1041
- } ) ;
1023
+ uploadStream . once ( 'finish' , function ( ) {
1024
+ const downloadStream = bucket . openDownloadStreamByName ( 'teststart.dat' , { start } ) . end ( end ) ;
1042
1025
1043
- downloadStream . on ( 'end' , function ( ) {
1044
- // Depending on different versions of node, we may get
1045
- // different amounts of 'data' events. node 0.10 gives 2,
1046
- // node >= 0.12 gives 3. Either is correct, but we just
1047
- // care that we got between 1 and 3, and got the right result
1048
- expect ( gotData >= 1 && gotData <= 3 ) . to . equal ( true ) ;
1049
- expect ( str ) . to . equal ( 'pache' ) ;
1050
- client . close ( done ) ;
1051
- } ) ;
1026
+ downloadStream . on ( 'error' , done ) ;
1027
+
1028
+ let str = '' ;
1029
+ downloadStream . on ( 'data' , function ( data ) {
1030
+ str += data . toString ( 'utf8' ) ;
1052
1031
} ) ;
1053
1032
1054
- readStream . pipe ( uploadStream ) ;
1033
+ downloadStream . on ( 'end' , function ( ) {
1034
+ expect ( str ) . to . equal ( 'pache' ) ;
1035
+ expect ( str ) . to . have . lengthOf ( end - start ) ;
1036
+ client . close ( done ) ;
1037
+ } ) ;
1055
1038
} ) ;
1039
+
1040
+ readStream . pipe ( uploadStream ) ;
1056
1041
}
1057
1042
} ) ;
1058
1043
0 commit comments