Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 58 lines (38 sloc) 1.068 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#include <node.h>
#include <node_buffer.h>
#include <node_version.h>
#include <v8.h>
#include "buffer_compat.h"


#if NODE_MINOR_VERSION < 3


char *BufferData(node::Buffer *b) {
  return b->data();
}


size_t BufferLength(node::Buffer *b) {
  return b->length();
}


char *BufferData(v8::Local<v8::Object> buf_obj) {
  v8::HandleScope scope;
  node::Buffer *buf = node::ObjectWrap::Unwrap<node::Buffer>(buf_obj);
  return buf->data();
}


size_t BufferLength(v8::Local<v8::Object> buf_obj) {
  v8::HandleScope scope;
  node::Buffer *buf = node::ObjectWrap::Unwrap<node::Buffer>(buf_obj);
  return buf->length();
}

#else // NODE_VERSION


char *BufferData(node::Buffer *b) {
  return node::Buffer::Data(b->handle_);
}


size_t BufferLength(node::Buffer *b) {
  return node::Buffer::Length(b->handle_);
}


char *BufferData(v8::Local<v8::Object> buf_obj) {
  v8::HandleScope scope;
  return node::Buffer::Data(buf_obj);
}


size_t BufferLength(v8::Local<v8::Object> buf_obj) {
  v8::HandleScope scope;
  return node::Buffer::Length(buf_obj);
}

#endif // NODE_VERSION
Something went wrong with that request. Please try again.