Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

state example using streaming api

  • Loading branch information...
commit 0a19090cedd6d641e82499fb8355e0ea983db897 1 parent d5f8b08
@tj tj authored
Showing with 8 additions and 2 deletions.
  1. +8 −2 examples/state.js
View
10 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");
+var out = fs.createWriteStream(__dirname + '/state.png')
+ , stream = canvas.createPNGStream();
+
+stream.on('data', function(chunk){
+ out.write(chunk);
+});
Please sign in to comment.
Something went wrong with that request. Please try again.