c++ - Buffering Bytes - Node.js Addon -
i want receive wav stream node.js (in add-on). implemented this:
readablestream.on('data', function(chunk) { var obj1 = addon.buffering(chunk);//my addon });
but want buffer information, , create copy of original wav. far can't populate new file bytes.
void buffering(const functioncallbackinfo<v8::value>& args) { isolate* isolate = isolate::getcurrent(); handlescope scope(isolate); local<object> bufferobj = args[0]->toobject(); char *buf = node::buffer::data(bufferobj); if (i == 0){ fp = fopen("copy.wav", "wb"); i++;} fwrite(buf, 1, sizeof(buf), fp); fflush(fp); if (i == 3){ fclose(fp); } i++; local<string> devolve = string::newfromutf8(isolate, "buffering_success");//c++--->js args.getreturnvalue().set(devolve); }
i don't understand why, sizeof(buf)
small. think because of that.
with precious tip of @mat:
nodejs:
readablestream.on('data', function(chunk) { console.log(chunk); var size = chunk.length;//<---size of chunk, matt console.log(size); var obj1 = addon.buffering(chunk,size); console.log('pass chunk'); });
addon:
void buffering(const functioncallbackinfo<v8::value>& args) { isolate* isolate = isolate::getcurrent(); handlescope scope(isolate); int size = args[1]->numbervalue(); local<object> bufferobj = args[0]->toobject(); char *buf = node::buffer::data(bufferobj); if (i == 0){ fp = fopen("copy.wav", "wb"); i++;} fwrite(buf, 1, size, fp); fflush(fp); if (i == 3){ fclose(fp); } i++; local<string> devolve = string::newfromutf8(isolate,"buffering_sucess");//c++--->js args.getreturnvalue().set(devolve); }
i remove iterator, "generic" solution. here because number of iterations occur.
Comments
Post a Comment