Search code examples
javascriptc++node.jsv8

How to convert V8::Value to binary string?


I post buffer(nodejs Buffer) in function:

Handle<Value> some::encrypt_buf (const Arguments& args) {
    String::AsciiValue abuf(args[0]->ToString());
    cout<<abuf.length()<<endl;
    char *buf=*abuf;
    ...
}

and get wrong length if buffer have some chars like \0 in buffer. How to get all binary chars to abuf and have correct length()? maybe exists best way to direct convert V8::Value to char* and length?


Solution

  • I decided to do so

    #include <node_buffer.h>
    ...
    Handle<Value> some::encrypt_buf (const Arguments& args) {
        int len=node::Buffer::Length(args[0]->ToObject());
        char *buf=Node::Buffer::Data(args[0]->ToObject());
        ...
    }
    

    why no official documentation of this? :-\ https://www.google.ru/webhp?q=%22node::buffer::data%22+site:nodejs.org