Use GridStore.readBuffer instead of GridStore.read #2

Closed
siddMahen opened this Issue Nov 5, 2011 · 3 comments

Comments

Projects
None yet
2 participants
@siddMahen
Owner

siddMahen commented Nov 5, 2011

So you don't have to worry about encoding nonsense.

@siddMahen

This comment has been minimized.

Show comment Hide comment
@siddMahen

siddMahen Nov 6, 2011

Owner

This should work:

var GridStream = require('GridFS').GridStream;
var assert = require('assert');
var fs = require('fs');

var test;
var s = '';

fs.readFile('1.txt.tar.gz', function(error, data) {
    test = data;
});

var stream = GridStream.createGridReadStream('test','1.txt.tar.gz');
stream.setEncoding('utf8');

stream.on('data', function(data){
    s += data;
});

stream.on('end', function(){

    console.log("Appear different:\n");
    //but contain the same data
    console.log(s);
    console.log(test);

    //same data so this passes
    assert.equal(s, test, "ERR: The buffers are not superficially equal!");

    //now the type is also going to be checked
    //so make this a string aswell
    assert.deepEqual(s, test.toString('utf8'), "ERR: The buffers are not truly equal!");
    console.log("Passes with GridStream.\n");
});
Owner

siddMahen commented Nov 6, 2011

This should work:

var GridStream = require('GridFS').GridStream;
var assert = require('assert');
var fs = require('fs');

var test;
var s = '';

fs.readFile('1.txt.tar.gz', function(error, data) {
    test = data;
});

var stream = GridStream.createGridReadStream('test','1.txt.tar.gz');
stream.setEncoding('utf8');

stream.on('data', function(data){
    s += data;
});

stream.on('end', function(){

    console.log("Appear different:\n");
    //but contain the same data
    console.log(s);
    console.log(test);

    //same data so this passes
    assert.equal(s, test, "ERR: The buffers are not superficially equal!");

    //now the type is also going to be checked
    //so make this a string aswell
    assert.deepEqual(s, test.toString('utf8'), "ERR: The buffers are not truly equal!");
    console.log("Passes with GridStream.\n");
});

@ghost ghost assigned siddMahen Nov 6, 2011

@siddMahen siddMahen closed this in 2ac4dd4 Nov 6, 2011

@siddMahen

This comment has been minimized.

Show comment Hide comment
@siddMahen

siddMahen Nov 6, 2011

Owner

To get a raw buffer from file without sending it through an encoding, use GridFS get() or use GridStream with node-buffertools to concat the buffers.

Owner

siddMahen commented Nov 6, 2011

To get a raw buffer from file without sending it through an encoding, use GridFS get() or use GridStream with node-buffertools to concat the buffers.

@chmoder

This comment has been minimized.

Show comment Hide comment
@chmoder

chmoder Mar 6, 2012

Ran across a small issue after the updates from node-mongodb-native. Didn't see the point in doing a pull request cause its only one function call.

/lib/GridFS.js
line 304

//old
gs.readBuffer(length, function(err, data){
//new
gs.read(length, function(err, data){

chmoder commented Mar 6, 2012

Ran across a small issue after the updates from node-mongodb-native. Didn't see the point in doing a pull request cause its only one function call.

/lib/GridFS.js
line 304

//old
gs.readBuffer(length, function(err, data){
//new
gs.read(length, function(err, data){
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment