Skip to content

Commit

Permalink
NODE-1034 Fix GridStore issue caused by Node 8.0.0 breaking backward …
Browse files Browse the repository at this point in the history
…compatible fs.read API
  • Loading branch information
christkv committed Jun 8, 2017
1 parent 388d4d2 commit 1298820
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/gridfs/grid_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,20 +427,23 @@ var writeFile = function(self, file, callback) {

// Write a chunk
var writeChunk = function() {
fs.read(file, self.chunkSize, offset, 'binary', function(err, data, bytesRead) {
// Allocate the buffer
var _buffer = new Buffer(self.chunkSize);
// Read the file
fs.read(file, _buffer, 0, _buffer.length, offset, function(err, bytesRead, data) {
if(err) return callback(err, self);

offset = offset + bytesRead;

// Create a new chunk for the data
var chunk = new Chunk(self, {n:index++}, self.writeConcern);
chunk.write(data, function(err, chunk) {
chunk.write(data.slice(0, bytesRead), function(err, chunk) {
if(err) return callback(err, self);

chunk.save({}, function(err) {
if(err) return callback(err, self);

self.position = self.position + data.length;
self.position = self.position + bytesRead;

// Point to current chunk
self.currentChunk = chunk;
Expand Down

0 comments on commit 1298820

Please sign in to comment.