lib/gridfs-stream/upload.js
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;

  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;

    var _this = this;
    checkIndexes(this, function() {
      _this.bucket.s.checkedIndexes = true;
      _this.bucket.emit('index');
    });
  }
}
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;

  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;

    var _this = this;
    checkIndexes(this, function() {
      _this.bucket.s.checkedIndexes = true;
      _this.bucket.emit('index');
    });
  }
}
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 ; 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 ; var _this = this ; checkIndexes ( this , function ( ) { _this . bucket . s . checkedIndexes = true ; _this . bucket . emit ( 'index' ) ; } ) ; } }
A writable stream that enables you to write buffers to GridFS.

Do not instantiate this class directly. Use `openUploadStream()` instead.

@class
@param {GridFSBucket} bucket Handle for this stream's corresponding bucket
@param {string} filename The value of the 'filename' key in the files doc
@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 {boolean} [options.disableMD5=false] If true, disables adding an md5 field to file data
@fires GridFSBucketWriteStream#error
@fires GridFSBucketWriteStream#finish
@return {GridFSBucketWriteStream} a GridFSBucketWriteStream instance.
A writable stream that enables you to write buffers to GridFS .