Skip to content

Instantly share code, notes, and snippets.

@dead-horse
Created August 20, 2012 09:31
Show Gist options
  • Save dead-horse/3402650 to your computer and use it in GitHub Desktop.
Save dead-horse/3402650 to your computer and use it in GitHub Desktop.
解析非utf8和ascii编码的buffer
#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