javascript - Pass Bytes to NodeJS Addon -
i want create stream wav file, , pass nodejs addon:
var readablestream = fs.createreadstream('random_file.wav'); readablestream.on('data', function(chunk) { var chunck_to_binary = chunk.tostring('what??'); //binary?? var obj1 = addon.store(chunck_to_binary); console.log('chunck'); console.log(obj1.caract_count); //console.log(typeof data); }); then, when file has been passed. want to devolve bytes nodejs, shure process correct. , create copy:
readablestream.on('end', function() { console.log("loaded"); var data_copy = addon.return_bytes(); fs.writefile('copy.wav', data_copy, function (err) { if (err) return console.log(err); console.log('done!!'); }); }); in addon implement this:
void store_values(const functioncallbackinfo<v8::value>& args) { isolate* isolate = isolate::getcurrent(); handlescope scope(isolate); if (args.length() < 1) { isolate->throwexception(exception::typeerror( string::newfromutf8(isolate, "wrong number of arguments"))); return; } v8::string::utf8value param1(args[0]->tostring()); std::string aux= std::string(*param1); //js---->c++ //file_in_memory global file_in_memory = file_in_memory + aux; //(..) return byte size of file_in_memory } so far have not succeed. possible wrong? think problem how passing information addon. suggestion?
chunk buffer, because it's chunk of bytes. pass add-on as-is:
var obj1 = addon.store(chunk); in add-on, can convert std::string so:
std::string aux(node::buffer::data(args[0]), node::buffer::length(args[0]));
Comments
Post a Comment