Skip to content

Commit 3fca2f8

Browse files
committed
Improved FrameworkImage.save().
1 parent f802e92 commit 3fca2f8

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

image.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ const sof = { 0xc0: true, 0xc1: true, 0xc2: true, 0xc3: true, 0xc5: true, 0xc6:
3131
var child = require('child_process');
3232
var exec = child.exec;
3333
var spawn = child.spawn;
34-
var path = require('path');
3534
var middlewares = {};
3635
var Fs = require('fs');
36+
var framework_utils = require('./utils');
3737

3838
function u16(buf, o) {
3939
return buf[o] << 8 | buf[o + 1];
@@ -140,7 +140,7 @@ function Image(filename, useImageMagick, width, height) {
140140
this.filename = type === 'string' ? filename : null;
141141
this.currentStream = type === 'object' ? filename : null;
142142
this.isIM = useImageMagick === undefined || useImageMagick === null ? F.config['default-image-converter'] === 'im' : useImageMagick;
143-
this.outputType = type === 'string' ? path.extname(filename).substring(1) : 'jpg';
143+
this.outputType = type === 'string' ? framework_utils.getExtension(filename).substring(1) : 'jpg';
144144
}
145145

146146
/*
@@ -250,11 +250,8 @@ Image.prototype.save = function(filename, callback, writer) {
250250
var writer = Fs.createWriteStream(filename + '_');
251251

252252
reader.pipe(middleware()).pipe(writer);
253-
254253
writer.on('finish', function() {
255-
Fs.rename(filename + '_', filename, function() {
256-
callback(null, true);
257-
});
254+
Fs.rename(filename + '_', filename, () => callback(null, true));
258255
});
259256
});
260257

@@ -804,3 +801,7 @@ exports.middleware = function(type, fn) {
804801
type = type.substring(1);
805802
middlewares[type] = fn;
806803
};
804+
805+
exports.restart = function() {
806+
middlewares = {};
807+
};

0 commit comments

Comments
 (0)