zhangyuanwei / node-images

Cross-platform image decoder(png/jpeg/gif) and encoder(png/jpeg) for Nodejs
https://npmjs.org/package/images
MIT License
1.56k stars 205 forks source link

add callback to save #33

Closed gkorland closed 5 years ago

gkorland commented 10 years ago

add callback to save

nitriques commented 9 years ago

I would really like that PR to get merged... Sync operation are bad.

Meanwhile, I wrote the function instead.

    images.Image.prototype.saveAsync = function (file, type, config, callback) {
        if (type && typeof(type) === 'object') {
            config = type;
            type = undefined;
        }
        if (!callback) {
            if (typeof type === 'function') {
                callback = type;
                type = undefined;
            }
            if (typeof config === 'function') {
                callback = config;
                config = undefined;
            }
        }
        fs.writeFile(file, this.encode(type || path.extname(file), config), callback);
        return this;
    };

Also, the save method should return this, like all the other ones.

nitriques commented 7 years ago

@zhangyuanwei can you please merge this! Thanks!

nitriques commented 7 years ago

Ho just saw it's already there! You can close!