Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(GridFS): fix TypeError: doc.data.length is not a function #1570

Merged
merged 1 commit into from
Nov 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions lib/gridfs-stream/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,29 +207,27 @@ function doRead(_this) {
return __handleError(_this, new Error(errmsg));
}

if (doc.data.length() !== expectedLength) {
var buf = Buffer.isBuffer(doc.data) ? doc.data : doc.data.buffer;

if (buf.length !== expectedLength) {
if (bytesRemaining <= 0) {
errmsg = 'ExtraChunk: Got unexpected n: ' + doc.n;
return __handleError(_this, new Error(errmsg));
}

errmsg =
'ChunkIsWrongSize: Got unexpected length: ' +
doc.data.length() +
', expected: ' +
expectedLength;
'ChunkIsWrongSize: Got unexpected length: ' + buf.length + ', expected: ' + expectedLength;
return __handleError(_this, new Error(errmsg));
}

_this.s.bytesRead += doc.data.length();
_this.s.bytesRead += buf.length;

if (doc.data.buffer.length === 0) {
if (buf.length === 0) {
return _this.push(null);
}

var sliceStart = null;
var sliceEnd = null;
var buf = doc.data.buffer;

if (_this.s.bytesToSkip != null) {
sliceStart = _this.s.bytesToSkip;
Expand All @@ -241,7 +239,7 @@ function doRead(_this) {
}

// If the remaining amount of data left is < chunkSize read the right amount of data
if (_this.s.options.end && _this.s.options.end - _this.s.bytesToSkip < doc.data.length()) {
if (_this.s.options.end && _this.s.options.end - _this.s.bytesToSkip < buf.length) {
sliceEnd = _this.s.options.end - _this.s.bytesToSkip;
}

Expand Down