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

是否在保存图片的时候可以加个完成回调? #77

Closed tces1 closed 8 years ago

big-pang commented 8 years ago

我也遇到了同样的问题!

zhangyuanwei commented 8 years ago

save同步操作

zhangyuanwei commented 8 years ago
  save: function(file, type, config) {
        if (type && typeof(type) == "object") {
            config = type;
            type = undefined;
        }
        fs.writeFileSync(file, this.encode(type || path.extname(file), config));
    }
zhangyuanwei commented 8 years ago

如果一定要异步。可以用这个:


    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;
    }
tces1 commented 8 years ago

thx ^_^