foliojs / png.js

A (animated) PNG decoder in JavaScript for the HTML5 canvas element and Node.js
http://devongovett.github.com/png.js
MIT License
489 stars 92 forks source link

offer async PNG.load() #26

Closed sdumetz closed 8 years ago

sdumetz commented 8 years ago

I don't see any reason for PNG.load() to be synchronous. I understand it can be a desired behavior but why not make something like :

PNG.load = function(path,callback) {
      var file;
      if(!callback){
        file = fs.readFileSync(path);
        return new PNG(file);
      }else{
        file = fs.readFile(path,function(err,file){
         if(err) callback(err);
         return callback(null,new PNG(file));
        });
      }
    };

Of course it's an improvisation and there may be cleaner ways to achieve it, but I think the core idea is useful.

My use case is : I'm only interested in text tags so PNG.decode is a no-go, but I still want async operations.

devongovett commented 8 years ago

Please use png-stream instead. It's better in almost every way.