Cleanup
This commit is contained in:
15
node_modules/mongodb/lib/gridfs-stream/download.js
generated
vendored
15
node_modules/mongodb/lib/gridfs-stream/download.js
generated
vendored
@@ -278,6 +278,7 @@ function init(self) {
|
||||
if (error) {
|
||||
return __handleError(self, error);
|
||||
}
|
||||
|
||||
if (!doc) {
|
||||
var identifier = self.s.filter._id ? self.s.filter._id.toString() : self.s.filter.filename;
|
||||
var errmsg = 'FileNotFound: file ' + identifier + ' was not found';
|
||||
@@ -301,7 +302,11 @@ function init(self) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.s.bytesToSkip = handleStartOption(self, doc, self.s.options);
|
||||
try {
|
||||
self.s.bytesToSkip = handleStartOption(self, doc, self.s.options);
|
||||
} catch (error) {
|
||||
return __handleError(self, error);
|
||||
}
|
||||
|
||||
var filter = { files_id: doc._id };
|
||||
|
||||
@@ -322,7 +327,13 @@ function init(self) {
|
||||
|
||||
self.s.expectedEnd = Math.ceil(doc.length / doc.chunkSize);
|
||||
self.s.file = doc;
|
||||
self.s.bytesToTrim = handleEndOption(self, doc, self.s.cursor, self.s.options);
|
||||
|
||||
try {
|
||||
self.s.bytesToTrim = handleEndOption(self, doc, self.s.cursor, self.s.options);
|
||||
} catch (error) {
|
||||
return __handleError(self, error);
|
||||
}
|
||||
|
||||
self.emit('file', doc);
|
||||
});
|
||||
}
|
||||
|
||||
67
node_modules/mongodb/lib/gridfs-stream/index.js
generated
vendored
67
node_modules/mongodb/lib/gridfs-stream/index.js
generated
vendored
@@ -7,6 +7,7 @@ var shallowClone = require('../utils').shallowClone;
|
||||
var toError = require('../utils').toError;
|
||||
var util = require('util');
|
||||
var executeLegacyOperation = require('../utils').executeLegacyOperation;
|
||||
const deprecateOptions = require('../utils').deprecateOptions;
|
||||
|
||||
var DEFAULT_GRIDFS_BUCKET_OPTIONS = {
|
||||
bucketName: 'fs',
|
||||
@@ -79,21 +80,28 @@ util.inherits(GridFSBucket, Emitter);
|
||||
* @param {object} [options.metadata] Optional object to store in the file document's `metadata` field
|
||||
* @param {string} [options.contentType] Optional string to store in the file document's `contentType` field
|
||||
* @param {array} [options.aliases] Optional array of strings to store in the file document's `aliases` field
|
||||
* @param {boolean} [options.disableMD5=false] If true, disables adding an md5 field to file data
|
||||
* @param {boolean} [options.disableMD5=false] **Deprecated** If true, disables adding an md5 field to file data
|
||||
* @return {GridFSBucketWriteStream}
|
||||
*/
|
||||
|
||||
GridFSBucket.prototype.openUploadStream = function(filename, options) {
|
||||
if (options) {
|
||||
options = shallowClone(options);
|
||||
} else {
|
||||
options = {};
|
||||
GridFSBucket.prototype.openUploadStream = deprecateOptions(
|
||||
{
|
||||
name: 'GridFSBucket.openUploadStream',
|
||||
deprecatedOptions: ['disableMD5'],
|
||||
optionsIndex: 1
|
||||
},
|
||||
function(filename, options) {
|
||||
if (options) {
|
||||
options = shallowClone(options);
|
||||
} else {
|
||||
options = {};
|
||||
}
|
||||
if (!options.chunkSizeBytes) {
|
||||
options.chunkSizeBytes = this.s.options.chunkSizeBytes;
|
||||
}
|
||||
return new GridFSBucketWriteStream(this, filename, options);
|
||||
}
|
||||
if (!options.chunkSizeBytes) {
|
||||
options.chunkSizeBytes = this.s.options.chunkSizeBytes;
|
||||
}
|
||||
return new GridFSBucketWriteStream(this, filename, options);
|
||||
};
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns a writable stream (GridFSBucketWriteStream) for writing
|
||||
@@ -107,25 +115,32 @@ GridFSBucket.prototype.openUploadStream = function(filename, options) {
|
||||
* @param {object} [options.metadata] Optional object to store in the file document's `metadata` field
|
||||
* @param {string} [options.contentType] Optional string to store in the file document's `contentType` field
|
||||
* @param {array} [options.aliases] Optional array of strings to store in the file document's `aliases` field
|
||||
* @param {boolean} [options.disableMD5=false] If true, disables adding an md5 field to file data
|
||||
* @param {boolean} [options.disableMD5=false] **Deprecated** If true, disables adding an md5 field to file data
|
||||
* @return {GridFSBucketWriteStream}
|
||||
*/
|
||||
|
||||
GridFSBucket.prototype.openUploadStreamWithId = function(id, filename, options) {
|
||||
if (options) {
|
||||
options = shallowClone(options);
|
||||
} else {
|
||||
options = {};
|
||||
GridFSBucket.prototype.openUploadStreamWithId = deprecateOptions(
|
||||
{
|
||||
name: 'GridFSBucket.openUploadStreamWithId',
|
||||
deprecatedOptions: ['disableMD5'],
|
||||
optionsIndex: 2
|
||||
},
|
||||
function(id, filename, options) {
|
||||
if (options) {
|
||||
options = shallowClone(options);
|
||||
} else {
|
||||
options = {};
|
||||
}
|
||||
|
||||
if (!options.chunkSizeBytes) {
|
||||
options.chunkSizeBytes = this.s.options.chunkSizeBytes;
|
||||
}
|
||||
|
||||
options.id = id;
|
||||
|
||||
return new GridFSBucketWriteStream(this, filename, options);
|
||||
}
|
||||
|
||||
if (!options.chunkSizeBytes) {
|
||||
options.chunkSizeBytes = this.s.options.chunkSizeBytes;
|
||||
}
|
||||
|
||||
options.id = id;
|
||||
|
||||
return new GridFSBucketWriteStream(this, filename, options);
|
||||
};
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns a readable stream (GridFSBucketReadStream) for streaming file
|
||||
|
||||
100
node_modules/mongodb/lib/gridfs-stream/upload.js
generated
vendored
100
node_modules/mongodb/lib/gridfs-stream/upload.js
generated
vendored
@@ -1,14 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
var core = require('../core');
|
||||
var crypto = require('crypto');
|
||||
var stream = require('stream');
|
||||
var util = require('util');
|
||||
var Buffer = require('safe-buffer').Buffer;
|
||||
|
||||
var ERROR_NAMESPACE_NOT_FOUND = 26;
|
||||
|
||||
module.exports = GridFSBucketWriteStream;
|
||||
const MONGODB_ERROR_CODES = require('../error_codes').MONGODB_ERROR_CODES;
|
||||
const core = require('../core');
|
||||
const crypto = require('crypto');
|
||||
const stream = require('stream');
|
||||
const util = require('util');
|
||||
const Buffer = require('safe-buffer').Buffer;
|
||||
const deprecateOptions = require('../utils').deprecateOptions;
|
||||
|
||||
/**
|
||||
* A writable stream that enables you to write buffers to GridFS.
|
||||
@@ -22,49 +20,58 @@ module.exports = GridFSBucketWriteStream;
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {string|number|object} [options.id] Custom file id for the GridFS file.
|
||||
* @param {number} [options.chunkSizeBytes] The chunk size to use, in bytes
|
||||
* @param {number} [options.w] The write concern
|
||||
* @param {number} [options.wtimeout] The write concern timeout
|
||||
* @param {number} [options.j] The journal write concern
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {boolean} [options.disableMD5=false] If true, disables adding an md5 field to file data
|
||||
* @fires GridFSBucketWriteStream#error
|
||||
* @fires GridFSBucketWriteStream#finish
|
||||
*/
|
||||
|
||||
function GridFSBucketWriteStream(bucket, filename, options) {
|
||||
options = options || {};
|
||||
this.bucket = bucket;
|
||||
this.chunks = bucket.s._chunksCollection;
|
||||
this.filename = filename;
|
||||
this.files = bucket.s._filesCollection;
|
||||
this.options = options;
|
||||
// Signals the write is all done
|
||||
this.done = false;
|
||||
const GridFSBucketWriteStream = deprecateOptions(
|
||||
{
|
||||
name: 'GridFSBucketWriteStream',
|
||||
deprecatedOptions: ['disableMD5'],
|
||||
optionsIndex: 2
|
||||
},
|
||||
function(bucket, filename, options) {
|
||||
options = options || {};
|
||||
stream.Writable.call(this, options);
|
||||
this.bucket = bucket;
|
||||
this.chunks = bucket.s._chunksCollection;
|
||||
this.filename = filename;
|
||||
this.files = bucket.s._filesCollection;
|
||||
this.options = options;
|
||||
// Signals the write is all done
|
||||
this.done = false;
|
||||
|
||||
this.id = options.id ? options.id : core.BSON.ObjectId();
|
||||
this.chunkSizeBytes = this.options.chunkSizeBytes;
|
||||
this.bufToStore = Buffer.alloc(this.chunkSizeBytes);
|
||||
this.length = 0;
|
||||
this.md5 = !options.disableMD5 && crypto.createHash('md5');
|
||||
this.n = 0;
|
||||
this.pos = 0;
|
||||
this.state = {
|
||||
streamEnd: false,
|
||||
outstandingRequests: 0,
|
||||
errored: false,
|
||||
aborted: false,
|
||||
promiseLibrary: this.bucket.s.promiseLibrary
|
||||
};
|
||||
this.id = options.id ? options.id : core.BSON.ObjectId();
|
||||
this.chunkSizeBytes = this.options.chunkSizeBytes;
|
||||
this.bufToStore = Buffer.alloc(this.chunkSizeBytes);
|
||||
this.length = 0;
|
||||
this.md5 = !options.disableMD5 && crypto.createHash('md5');
|
||||
this.n = 0;
|
||||
this.pos = 0;
|
||||
this.state = {
|
||||
streamEnd: false,
|
||||
outstandingRequests: 0,
|
||||
errored: false,
|
||||
aborted: false,
|
||||
promiseLibrary: this.bucket.s.promiseLibrary
|
||||
};
|
||||
|
||||
if (!this.bucket.s.calledOpenUploadStream) {
|
||||
this.bucket.s.calledOpenUploadStream = true;
|
||||
if (!this.bucket.s.calledOpenUploadStream) {
|
||||
this.bucket.s.calledOpenUploadStream = true;
|
||||
|
||||
var _this = this;
|
||||
checkIndexes(this, function() {
|
||||
_this.bucket.s.checkedIndexes = true;
|
||||
_this.bucket.emit('index');
|
||||
});
|
||||
var _this = this;
|
||||
checkIndexes(this, function() {
|
||||
_this.bucket.s.checkedIndexes = true;
|
||||
_this.bucket.emit('index');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
util.inherits(GridFSBucketWriteStream, stream.Writable);
|
||||
|
||||
@@ -208,7 +215,7 @@ function checkChunksIndex(_this, callback) {
|
||||
_this.chunks.listIndexes().toArray(function(error, indexes) {
|
||||
if (error) {
|
||||
// Collection doesn't exist so create index
|
||||
if (error.code === ERROR_NAMESPACE_NOT_FOUND) {
|
||||
if (error.code === MONGODB_ERROR_CODES.NamespaceNotFound) {
|
||||
var index = { files_id: 1, n: 1 };
|
||||
_this.chunks.createIndex(index, { background: false, unique: true }, function(error) {
|
||||
if (error) {
|
||||
@@ -282,6 +289,7 @@ function checkDone(_this, callback) {
|
||||
return __handleError(_this, error, callback);
|
||||
}
|
||||
_this.emit('finish', filesDoc);
|
||||
_this.emit('close');
|
||||
});
|
||||
|
||||
return true;
|
||||
@@ -306,7 +314,7 @@ function checkIndexes(_this, callback) {
|
||||
_this.files.listIndexes().toArray(function(error, indexes) {
|
||||
if (error) {
|
||||
// Collection doesn't exist so create index
|
||||
if (error.code === ERROR_NAMESPACE_NOT_FOUND) {
|
||||
if (error.code === MONGODB_ERROR_CODES.NamespaceNotFound) {
|
||||
var index = { filename: 1, uploadDate: 1 };
|
||||
_this.files.createIndex(index, { background: false }, function(error) {
|
||||
if (error) {
|
||||
@@ -536,3 +544,5 @@ function checkAborted(_this, callback) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = GridFSBucketWriteStream;
|
||||
|
||||
Reference in New Issue
Block a user