Skip to content

Commit

Permalink
fix node 7.x deprication warnings, update to latest on-finished lib
Browse files Browse the repository at this point in the history
  • Loading branch information
joelabair committed Jan 26, 2017
1 parent bd0e0d6 commit 1a7892d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var fs = require('fs'),
util = require('util'),
finished = require('finished'),
finished = require('on-finished'),
debug = require('debug')('multer-autoreap:middleware');


Expand All @@ -23,25 +23,28 @@ module.exports = function(req, res, next) {
}
fs.stat(file.path, function(err, stats) {
if (!err && stats.isFile()) {
fs.unlink(file.path);
debug('removed %s', file.path);
res.emit('autoreap', file);
fs.unlink(file.path, function(err) {
if (err ) return console.warn(err);
debug('removed %s', file.path);
res.emit('autoreap', file);
});
}
});
};

var reapFiles = function reapFiles(err) {
var file, done = [];
var mapFn = function(file) {
processFile(err, file);
};
if (typeof req.files === "object") {
for(var key in req.files) {
if (Object.prototype.hasOwnProperty.call(req.files, key) && !~done.indexOf(key)) {
file = req.files[key];
if (!(file instanceof Array)) {
file = [file];
}
file.forEach(function(file) {
processFile(err, file);
});
file.forEach(mapFn);
done.push(key);
}
}
Expand All @@ -52,11 +55,8 @@ module.exports = function(req, res, next) {
}
};

res.on('error', function(err) {
reapFiles(err);
});
finished(res, reapFiles);

finished(res, reapFiles);
next();

};
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "multer-autoreap",
"version": "0.1.2",
"version": "0.1.3",
"description": "Connect middleware providing auto gc of tmp uploaded files by multer or any multipart middleware.",
"license": "GPL-2.0+",
"main": "index.js",
Expand All @@ -27,7 +27,7 @@
},
"dependencies": {
"debug": "^2.2.0",
"finished": "^1.2.2"
"on-finished": "^2.3.0"
},
"devDependencies": {
"chai": "^3.5.x",
Expand Down

0 comments on commit 1a7892d

Please sign in to comment.