Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-847

GridFSBucket can't write a static buffer in few chunks

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Gone away
    • Affects Version/s: 2.2.10
    • Fix Version/s: None
    • Component/s: MongoDB 3.2
    • Labels:
      None
    • Environment:
      Node.js 4

      Description

      Let's say I have a StaticBuffer which it's size is 2X bytes where the default chunkSizeBytes is X.

      this is my starting code:

      var bucket = new mongodb.GridFSBucket(db);
      var writer = bucket.openUploadStreamWithId(fileId, null, {contentType: ContentType});
      writer.on('finish', function () {
          return true;
      }).on('error', function (Error) {
          return Error;
      });
       
      writer.end(StaticBuffer);
      

      When doing this, the app will crash because it is trying to close the stream twice.
      But also when trying to write and then end like this:

      writer.write(StaticBuffer, null, function () {
          writer.end(null)
      });
      

      the problem will persist because the end will be called before all chunks are done flushing to the db.

      The only way to workaround this, is to define the chunkSizeBytes to be bigger than the StaticBuffer and using only the end function in the following way:

      var bucket = new mongodb.GridFSBucket(db);
      var writer = bucket.openUploadStreamWithId(fileId, null, {chunkSizeBytes: StaticBuffer.length + 1, contentType: ContentType});
      writer.on('finish', function () {
          return true;
      }).on('error', function (Error) {
          return Error;
      });
       
      writer.end(StaticBuffer);
      

      But I want my buffer to be saved in multiple chunks which doesn't seems possible.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            tomgrossman Tom Grossman
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: