From 1a7892d276ecb30f9548e45b30b133c2efbda031 Mon Sep 17 00:00:00 2001 From: "Joel A. Bair" Date: Thu, 26 Jan 2017 11:53:04 -0700 Subject: [PATCH] fix node 7.x deprication warnings, update to latest on-finished lib --- index.js | 22 +++++++++++----------- package.json | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 01f4571..2dc3301 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ var fs = require('fs'), util = require('util'), - finished = require('finished'), + finished = require('on-finished'), debug = require('debug')('multer-autoreap:middleware'); @@ -23,15 +23,20 @@ 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)) { @@ -39,9 +44,7 @@ module.exports = function(req, res, next) { if (!(file instanceof Array)) { file = [file]; } - file.forEach(function(file) { - processFile(err, file); - }); + file.forEach(mapFn); done.push(key); } } @@ -52,11 +55,8 @@ module.exports = function(req, res, next) { } }; - res.on('error', function(err) { - reapFiles(err); - }); + finished(res, reapFiles); - finished(res, reapFiles); next(); }; diff --git a/package.json b/package.json index 0609562..a2c8735 100644 --- a/package.json +++ b/package.json @@ -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", @@ -27,7 +27,7 @@ }, "dependencies": { "debug": "^2.2.0", - "finished": "^1.2.2" + "on-finished": "^2.3.0" }, "devDependencies": { "chai": "^3.5.x",