From b50e6e891ced5f72139f7c12c11eedc9d1fad9e4 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Wed, 3 Nov 2010 14:29:50 -0700 Subject: [PATCH] spark example using streaming api --- examples/spark.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/spark.js b/examples/spark.js index 77ebd74..1f2dd11 100644 --- a/examples/spark.js +++ b/examples/spark.js @@ -5,7 +5,8 @@ var Canvas = require('../lib/canvas') , canvas = new Canvas(40, 15) - , ctx = canvas.getContext('2d'); + , ctx = canvas.getContext('2d') + , fs = require('fs'); Object.defineProperty(Array.prototype, 'max', { get: function(){ @@ -39,4 +40,9 @@ function spark(ctx, data) { spark(ctx, [1,2,4,5,10,4,2,5,4,3,3,2]); -canvas.savePNG(__dirname + "/spark.png"); \ No newline at end of file +var out = fs.createWriteStream(__dirname + '/spark.png') + , stream = canvas.createPNGStream(); + +stream.on('data', function(chunk){ + out.write(chunk); +}); \ No newline at end of file