Created
February 13, 2011 05:30
-
-
Save marcello3d/824478 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GridStore.prototype.getStream = function() { | |
var self = this; | |
var stream = new (require("stream")).Stream; | |
stream.readable = true; | |
process.nextTick(function() { | |
self.chunkCollection(function(err, collection) { | |
collection.find({'files_id':self.fileId}, function(err, cursor) { | |
function handleChunk(err, chunk) { | |
if (chunk) { | |
stream.emit('data', chunk.data.buffer) | |
cursor.nextObject(handleChunk) | |
} else { | |
stream.readable = false; | |
stream.emit('end'); | |
} | |
} | |
cursor.nextObject(handleChunk) | |
}); | |
}); | |
}) | |
return stream; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment