diff --git a/examples/text.js b/examples/text.js index 02c5ab2..3d00a08 100644 --- a/examples/text.js +++ b/examples/text.js @@ -5,7 +5,8 @@ var Canvas = require('../lib/canvas') , canvas = new Canvas(200, 200) - , ctx = canvas.getContext('2d'); + , ctx = canvas.getContext('2d') + , fs = require('fs'); ctx.globalAlpha = .2; @@ -32,4 +33,9 @@ ctx.strokeText("Wahoo", 50, 100); ctx.fillStyle = '#000'; ctx.fillText("Wahoo", 49, 99); -canvas.savePNG(__dirname + '/text.png'); \ No newline at end of file +var out = fs.createWriteStream(__dirname + '/text.png') + , stream = canvas.createPNGStream(); + +stream.on('data', function(chunk){ + out.write(chunk); +}); \ No newline at end of file diff --git a/lib/canvas.js b/lib/canvas.js index 3f519f5..641aff4 100644 --- a/lib/canvas.js +++ b/lib/canvas.js @@ -15,7 +15,8 @@ var canvas = require('../build/default/canvas') , Context2d = canvas.CanvasRenderingContext2d , CanvasGradient = canvas.CanvasGradient , cairoVersion = canvas.cairoVersion - , PNGStream = require('./pngstream'); + , PNGStream = require('./pngstream') + , fs = require('fs'); /** * Export `Canvas` as the module. diff --git a/lib/pngstream.js b/lib/pngstream.js index a897abc..2f3ecf6 100644 --- a/lib/pngstream.js +++ b/lib/pngstream.js @@ -41,7 +41,8 @@ var PNGStream = module.exports = function PNGStream(canvas, sync) { : 'streamPNG'; this.sync = sync; this.canvas = canvas; - if ('streamPNG' == method) throw new Error('async png streaming not yet implemented'); + // TODO: implement async + if ('streamPNG' == method) method = 'streamPNGSync'; process.nextTick(function(){ canvas[method](function(err, chunk, len){ if (err) {