Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Gif now returns a Buffer

  • Loading branch information...
commit aab504d38fded376de6b28eb9d6afe874ce331e9 1 parent 78b4994
@pkrumins authored
Showing with 9 additions and 6 deletions.
  1. +7 −4 src/gif.cpp
  2. +1 −1  tests/gif-async.js
  3. +1 −1  tests/gif.js
View
11 src/gif.cpp
@@ -34,9 +34,10 @@ Gif::GifEncodeSync()
encoder.set_transparency_color(transparency_color);
}
encoder.encode();
- return scope.Close(
- Encode((char *)encoder.get_gif(), encoder.get_gif_len(), BINARY)
- );
+ int gif_len = encoder.get_gif_len();
+ Buffer *retbuf = Buffer::New(gif_len);
+ memcpy(retbuf->data(), encoder.get_gif(), gif_len);
+ return scope.Close(retbuf->handle_);
}
catch (const char *err) {
return VException(err);
@@ -179,7 +180,9 @@ Gif::EIO_GifEncodeAfter(eio_req *req)
argv[1] = ErrorException(enc_req->error);
}
else {
- argv[0] = Local<Value>::New(Encode(enc_req->gif, enc_req->gif_len, BINARY));
+ Buffer *buf = Buffer::New(enc_req->gif_len);
+ memcpy(buf->data(), enc_req->gif, enc_req->gif_len);
+ argv[0] = buf->handle_;
argv[1] = Undefined();
}
View
2  tests/gif-async.js
@@ -8,7 +8,7 @@ var terminal = fs.readFileSync('./terminal.rgb');
var gif = new Gif(terminal, 720, 400, 'rgb');
gif.encode(function (data) {
- fs.writeFileSync('./terminal-async.gif', data, 'binary');
+ fs.writeFileSync('./terminal-async.gif', data.toString('binary'), 'binary');
});
View
2  tests/gif.js
@@ -7,5 +7,5 @@ var terminal = fs.readFileSync('./terminal.rgb');
var gif = new Gif(terminal, 720, 400, 'rgb').encodeSync();
-fs.writeFileSync('./terminal.gif', gif, 'binary');
+fs.writeFileSync('./terminal.gif', gif.toString('binary'), 'binary');
Please sign in to comment.
Something went wrong with that request. Please try again.