0

v8 から javascript に char ポインタを返したいのですが、うまくいきません。js では結果の長さが良くありません。たとえば、outlength は v8 では 43529 バイトですが、js では 4 バイトしかありません。return String::New((char *)img); の使用は正しいですか?

Javascript:

var result = module.encode();
console.log(result.length);

V8

Handle<Value> encode(const Arguments& args) {

  FILE *pInputFile = fopen ( "images/file.rgb" , "rb" );
    if (!pInputFile ) {
    fprintf(stderr, "Could not open %s\n", "vr.rgb");
    exit(1);
   }
   fseek (pInputFile , 0 , SEEK_END);
   long lSizeInput = ftell (pInputFile );
   rewind (pInputFile );
   char *img=(char*) malloc(lSizeInput*sizeof( char ));
   fread (img,1,lSizeInput,pInputFile);

   cout<<"length = "<< lSizeInput<<endl;
   return  String::New((char *)img);

}
4

0 に答える 0