lib/s3-upload-stream.js
function () {
    // Combine the buffers we've received and reset the list of buffers.
    var combinedBuffer = Buffer.concat(receivedBuffers, receivedBuffersLength);
    receivedBuffers.length = 0; // Trick to reset the array while keeping the original reference
    receivedBuffersLength = 0;

    if (combinedBuffer.length > partSizeThreshold) {
      // The combined buffer is too big, so slice off the end and put it back in the array.
      var remainder = new Buffer(combinedBuffer.length - partSizeThreshold);
      combinedBuffer.copy(remainder, 0, partSizeThreshold);
      receivedBuffers.push(remainder);
      receivedBuffersLength = remainder.length;

      // Return the perfectly sized part.
      var uploadBuffer = new Buffer(partSizeThreshold);
      combinedBuffer.copy(uploadBuffer, 0, 0, partSizeThreshold);
      return uploadBuffer;
    }
    else {
      // It just happened to be perfectly sized, so return it.
      return combinedBuffer;
    }
  }
function () {
    // Combine the buffers we've received and reset the list of buffers.
    var combinedBuffer = Buffer.concat(receivedBuffers, receivedBuffersLength);
    receivedBuffers.length = 0; // Trick to reset the array while keeping the original reference
    receivedBuffersLength = 0;

    if (combinedBuffer.length > partSizeThreshold) {
      // The combined buffer is too big, so slice off the end and put it back in the array.
      var remainder = new Buffer(combinedBuffer.length - partSizeThreshold);
      combinedBuffer.copy(remainder, 0, partSizeThreshold);
      receivedBuffers.push(remainder);
      receivedBuffersLength = remainder.length;

      // Return the perfectly sized part.
      var uploadBuffer = new Buffer(partSizeThreshold);
      combinedBuffer.copy(uploadBuffer, 0, 0, partSizeThreshold);
      return uploadBuffer;
    }
    else {
      // It just happened to be perfectly sized, so return it.
      return combinedBuffer;
    }
  }
function ( ) { // Combine the buffers we've received and reset the list of buffers. var combinedBuffer = Buffer . concat ( receivedBuffers , receivedBuffersLength ) ; receivedBuffers . length = 0 ; // Trick to reset the array while keeping the original reference receivedBuffersLength = 0 ; if ( combinedBuffer . length > partSizeThreshold ) { // The combined buffer is too big, so slice off the end and put it back in the array. var remainder = new Buffer ( combinedBuffer . length - partSizeThreshold ) ; combinedBuffer . copy ( remainder , 0 , partSizeThreshold ) ; receivedBuffers . push ( remainder ) ; receivedBuffersLength = remainder . length ; // Return the perfectly sized part. var uploadBuffer = new Buffer ( partSizeThreshold ) ; combinedBuffer . copy ( uploadBuffer , 0 , 0 , partSizeThreshold ) ; return uploadBuffer ; } else { // It just happened to be perfectly sized, so return it. return combinedBuffer ; } }
Take a list of received buffers and return a combined buffer that is exactly partSizeThreshold in size.
Take a list of received buffers and return a combined buffer that is exactly partSizeThreshold in size .