diff --git a/lib/buffer.js b/lib/buffer.js index 6b5fb20..6787881 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -19,4 +19,14 @@ Buffer.prototype.concat = function(other) { this.copy(buf, 0, 0); other.copy(buf, len, 0); return buf; -}; \ No newline at end of file +}; + +// patch if not v0.2 of node.js and Buffer.isBuffer fails for SlowBuffer +if (process.version.indexOf("v0.2") == -1) { + var SlowBuffer = process.binding('buffer').SlowBuffer; + if (!Buffer.isBuffer(new SlowBuffer(10))) { + Buffer.isBuffer = function (b) { + return (b instanceof Buffer) || (b instanceof SlowBuffer); + }; + } +} \ No newline at end of file diff --git a/package.json b/package.json index 4766c80..072e950 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,6 @@ , "scripts": { "preinstall": "node-waf configure build" } - , "engines": { "node": ">= 0.2.3 < 0.3.0" } + , "engines": { "node": ">= 0.3.0" } , "main": "./lib/canvas.js" } \ No newline at end of file diff --git a/src/Canvas.cc b/src/Canvas.cc index 6f2f013..f0c2e21 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -8,6 +8,7 @@ #include "Canvas.h" #include #include +#include using namespace v8; using namespace node; @@ -109,7 +110,11 @@ static cairo_status_t writeToBuffer(void *c, const uint8_t *data, unsigned len) { closure_t *closure = (closure_t *) c; Buffer *buf = Buffer::New(len); +#if NODE_VERSION_AT_LEAST(0,3,0) + memcpy(Buffer::Data(buf->handle_), data, len); +#else memcpy(buf->data(), data, len); +#endif Handle argv[3] = { Null(), buf->handle_, Integer::New(len) }; closure->fn->Call(Context::GetCurrent()->Global(), 3, argv); return CAIRO_STATUS_SUCCESS;