Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added buffer compatibility helpers to avoid node version conflicts

  • Loading branch information...
commit b86cfa653586e247bd5bd889990056d22af771a9 1 parent 25f5f85
@elbart elbart authored
Showing with 73 additions and 0 deletions.
  1. +58 −0 src/buffer_compat.cpp
  2. +15 −0 src/buffer_compat.h
View
58 src/buffer_compat.cpp
@@ -0,0 +1,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
View
15 src/buffer_compat.h
@@ -0,0 +1,15 @@
+#ifndef buffer_compat_h
+#define buffer_compat_h
+
+#include <node.h>
+#include <node_buffer.h>
+#include <v8.h>
+
+char *BufferData(node::Buffer *b);
+size_t BufferLength(node::Buffer *b);
+
+char *BufferData(v8::Local<v8::Object> buf_obj);
+size_t BufferLength(v8::Local<v8::Object> buf_obj);
+
+
+#endif // buffer_compat_h
Please sign in to comment.
Something went wrong with that request. Please try again.