|
1 | 1 | 'use strict';
|
2 | 2 |
|
| 3 | +const stream = require('stream'); |
3 | 4 | const crypto = require('crypto'),
|
4 | 5 | EJSON = require('mongodb-extjson'),
|
5 | 6 | fs = require('fs'),
|
@@ -1036,6 +1037,47 @@ describe('GridFS Stream', function() {
|
1036 | 1037 | }
|
1037 | 1038 | });
|
1038 | 1039 |
|
| 1040 | + it('should use chunkSize for download', { |
| 1041 | + metadata: { requires: { topology: ['single'] } }, |
| 1042 | + |
| 1043 | + // The actual test we wish to run |
| 1044 | + test: function(done) { |
| 1045 | + if (typeof stream.pipeline !== 'function') { |
| 1046 | + this.skip(); |
| 1047 | + } |
| 1048 | + |
| 1049 | + const configuration = this.configuration; |
| 1050 | + const GridFSBucket = configuration.require.GridFSBucket; |
| 1051 | + |
| 1052 | + const client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 }); |
| 1053 | + client.connect(function(err, client) { |
| 1054 | + const db = client.db(configuration.db); |
| 1055 | + const bucket = new GridFSBucket(db, { bucketName: 'gridfs' }); |
| 1056 | + |
| 1057 | + const uploadStream = bucket.openUploadStream('test'); |
| 1058 | + uploadStream.end(Buffer.alloc(40 * 1024 * 1024), err => { |
| 1059 | + expect(err).to.be.null; |
| 1060 | + const range = { |
| 1061 | + start: 35191617, |
| 1062 | + end: 35192831 |
| 1063 | + }; |
| 1064 | + const downloadStream = bucket.openDownloadStreamByName('test', range); |
| 1065 | + const outputStream = fs.createWriteStream('output'); |
| 1066 | + stream.pipeline(downloadStream, outputStream, err => { |
| 1067 | + expect(err).to.not.exist; |
| 1068 | + client.close(() => { |
| 1069 | + fs.stat('output', (err, stats) => { |
| 1070 | + expect(err).to.be.null; |
| 1071 | + expect(range.end - range.start).to.equal(stats.size); |
| 1072 | + done(); |
| 1073 | + }); |
| 1074 | + }); |
| 1075 | + }); |
| 1076 | + }); |
| 1077 | + }); |
| 1078 | + } |
| 1079 | + }); |
| 1080 | + |
1039 | 1081 | var UPLOAD_SPEC = require('./spec/gridfs/gridfs-upload.json');
|
1040 | 1082 | UPLOAD_SPEC.tests.forEach(function(specTest) {
|
1041 | 1083 | (function(testSpec) {
|
|
0 commit comments