Skip to content

Instantly share code, notes, and snippets.

@marcello3d
Created February 13, 2011 05:30
Show Gist options
  • Save marcello3d/824478 to your computer and use it in GitHub Desktop.
Save marcello3d/824478 to your computer and use it in GitHub Desktop.
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