Question

I'm working in Meteor.js with the recorderJs library, and trying to store stereo audio buffers to MongoDB.

On the client, console.log(buffers) gives an array of the form

[Float32Array, Float32Array]

But after passing it to Meteor.methods with Meteor.call('newSound', buffers) with the method

Meteor.methods({
    newSound: function(buffers) {
        console.log(buffers);
    }
}

I get an array like this:

[Object, Object]

Why is Meteor converting the arrays to objects? Upon retrieval, I need to work with the data as array buffers, and can re-convert them with

var buffers = new Array(
    _.toArray(buffers[0]),
    _.toArray(buffers[1])
);

but I'm concerned about performance. Should I be converting the buffers to blobs before storing them to the database, then reconverting when I retrieve them?

Was it helpful?

Solution

Only EJSON compatible types will be automatically converted from JSON objects to their actual JavaScript type. Read about EJSON here:

http://docs.meteor.com/#ejson

I don't believe Float32Array has been made EJSON compatible by the Meteor team. For more information on EJSON and how you can make a type compatible, watch these videos:

There is also EJSON.newBinary() which may be helpful for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top