Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pngStream End Before File is writen #802

Closed
pyromanci opened this issue Aug 25, 2016 · 3 comments
Closed

pngStream End Before File is writen #802

pyromanci opened this issue Aug 25, 2016 · 3 comments

Comments

@pyromanci
Copy link

Issue or Feature

I'm currently working on a script that takes the output from a roll20 API wrote and merge the map data down to a single image. This was due to the fact that a couple of my maps are so big that a few of my maps were so large with so many different elements it was crashing a few of my players.

So i wrote this to rebuild the map in a canvas and save it off as a single PNG. The problem is when i do this. I seem to get the 'saved png' message far before the actually file is finished being written.

The Final PNG size in my tests was almost 300MB in size.

Steps to Reproduce

var fs = require('fs')
, out = fs.createWriteStream(__dirname + '/text.png')
, stream = canvas.pngStream();

stream.on('data', function(chunk){
out.write(chunk);
});

stream.on('end', function(){
console.log('saved png');
});

Your Environment

  • Version of node-canvas (e.g. 1.4.0): 1.4.0
  • Environment: Centos 6 Linux 3.10.101-1.el6.elrepo.x86_64 Expose cairo version #1 SMP Wed Mar 16 20:55:27 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux
@LinusU
Copy link
Collaborator

LinusU commented Aug 27, 2016

This is expected, end only mean that the data has ended from the stream. If you want to know when the file is written, you'll have to listen to the finish event on the file writer.

out.on('finish', () => console.log('saved png'))

@LinusU LinusU closed this as completed Aug 27, 2016
@mathiasbynens
Copy link
Contributor

@LinusU In that case, we may want to update this README example: https://github.com/Automattic/node-canvas#canvaspngstreamoptions

@LinusU
Copy link
Collaborator

LinusU commented Nov 24, 2017

Great catch! I’m on mobile now so can’t do it myself, PR welcome or I’ll fix it after the weekend :)

mathiasbynens added a commit to mathiasbynens/node-canvas that referenced this issue Nov 24, 2017
LinusU added a commit that referenced this issue Nov 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants