Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Png now returns a Buffer again (ok way in sync interface and lousy wa…

…y in async interface)
  • Loading branch information...
commit 2b89cf54a7f85280e85883dd0b73c0c6a2329a74 1 parent a2bfa5f
@pkrumins authored
View
2  examples/png-example-async.js
@@ -12,6 +12,6 @@ png.encode(function (data, error) {
console.log('Error: ' + error.toString());
process.exit(1);
}
- fs.writeFileSync('./png-async.png', data, 'binary');
+ fs.writeFileSync('./png-async.png', data.toString('binary'), 'binary');
});
View
7 examples/png-example.js
@@ -1,14 +1,11 @@
var fs = require('fs');
var sys = require('sys');
var Png = require('../png').Png;
-var Buffer = require('buffer').Buffer;
-// the rgba-terminal.dat file is 1152000 bytes long.
-var rgba = new Buffer(1152000);
-rgba.write(fs.readFileSync('./rgba-terminal.dat', 'binary'), 'binary');
+var rgba = fs.readFileSync('./rgba-terminal.dat');
var png = new Png(rgba, 720, 400, 'rgba');
var png_image = png.encodeSync();
-fs.writeFileSync('./png.png', png_image, 'binary');
+fs.writeFileSync('./png.png', png_image.toString('binary'), 'binary');
View
2  examples/png-example2.js
@@ -18,5 +18,5 @@ rgba.write(img, 'binary');
var png = new Png(rgba, 5, 5, 'rgba');
var png_image = png.encodeSync();
-fs.writeFileSync('./png-5x5.png', png_image, 'binary');
+fs.writeFileSync('./png-5x5.png', png_image.toString('binary'), 'binary');
View
2  examples/png-example3.js
@@ -17,5 +17,5 @@ for (var i=0; i<HEIGHT; i++) {
var png = new Png(rgb, WIDTH, HEIGHT, 'rgb');
-fs.writeFileSync('./png-gradient.png', png.encodeSync(), 'binary');
+fs.writeFileSync('./png-gradient.png', png.encodeSync().toString('binary'), 'binary');
View
13 src/png.cpp
@@ -28,9 +28,12 @@ Png::PngEncodeSync()
HandleScope scope;
try {
- PngEncoder p((unsigned char *)data->data(), width, height, buf_type);
- p.encode();
- return scope.Close(Encode((char *)p.get_png(), p.get_png_len(), BINARY));
+ PngEncoder encoder((unsigned char *)data->data(), width, height, buf_type);
+ encoder.encode();
+ int png_len = encoder.get_png_len();
+ Buffer *retbuf = Buffer::New(png_len);
+ memcpy(retbuf->data(), encoder.get_png(), png_len);
+ return scope.Close(retbuf->handle_);
}
catch (const char *err) {
return VException(err);
@@ -138,7 +141,9 @@ Png::EIO_PngEncodeAfter(eio_req *req)
argv[1] = ErrorException(enc_req->error);
}
else {
- argv[0] = Local<Value>::New(Encode(enc_req->png, enc_req->png_len, BINARY));
+ Buffer *buf = Buffer::New(enc_req->png_len);
+ memcpy(buf->data(), enc_req->png, enc_req->png_len);
+ argv[0] = buf->handle_;
argv[1] = Undefined();
}
Please sign in to comment.
Something went wrong with that request. Please try again.