From 0a19090cedd6d641e82499fb8355e0ea983db897 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Wed, 3 Nov 2010 14:29:10 -0700 Subject: [PATCH] state example using streaming api --- examples/state.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/state.js b/examples/state.js index f83975b..4b59c5e 100644 --- a/examples/state.js +++ b/examples/state.js @@ -5,7 +5,8 @@ var Canvas = require('../lib/canvas') , canvas = new Canvas(150, 150) - , ctx = canvas.getContext('2d'); + , ctx = canvas.getContext('2d') + , fs = require('fs'); ctx.fillRect(0,0,150,150); // Draw a rectangle with default settings ctx.save(); // Save the default state @@ -24,4 +25,9 @@ ctx.fillRect(45,45,60,60); // Draw a rectangle with restored settings ctx.restore(); // Restore original state ctx.fillRect(60,60,30,30); // Draw a rectangle with restored settings -canvas.savePNG(__dirname + "/state.png"); \ No newline at end of file +var out = fs.createWriteStream(__dirname + '/state.png') + , stream = canvas.createPNGStream(); + +stream.on('data', function(chunk){ + out.write(chunk); +}); \ No newline at end of file