Created
August 20, 2012 09:31
-
-
Save dead-horse/3402650 to your computer and use it in GitHub Desktop.
解析非utf8和ascii编码的buffer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <node.h> | |
#include <v8.h> | |
#include <node_buffer.h> | |
#include <iostream> | |
using namespace std; | |
using namespace v8; | |
using namespace node; | |
Handle<Value> test(const Arguments& args) { | |
HandleScope scope; | |
char a[3] = {13, 1, 1, 0, 0, -123}; | |
//return scope.Close(Buffer::New(String::New(a))); //会被第四个字符0截断 | |
//return scope.Close(Buffer::New(String::New(a, 6))); //无法解析成utf-8或者iscii,转换错误 | |
return scope.Close(Buffer::New(a, 6)->handle_); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment