diff --git a/binding.js b/binding.js index fb97c642..93eb9e37 100644 --- a/binding.js +++ b/binding.js @@ -25,7 +25,7 @@ var isFile = function(file) { return exists; }; -var unpack = function(tarPath) { +var unpack = function(tarPath, done) { var extractor = tar.Extract({ path: __dirname }); @@ -34,6 +34,9 @@ var unpack = function(tarPath) { if (!isFile(vipsHeaderPath)) { error('Could not unpack ' + tarPath); } + if (typeof done === 'function') { + done(); + } }); fs.createReadStream(tarPath).on('error', error) .pipe(zlib.Unzip()) @@ -73,10 +76,15 @@ module.exports.download_vips = function() { if (isFile(tarPath)) { unpack(tarPath); } else { - // Download - tarPath = path.join(tmp, tarFilename); + // Download to per-process temporary file + tarPath = path.join(tmp, process.pid + '-' + tarFilename); var tmpFile = fs.createWriteStream(tarPath).on('finish', function() { - unpack(tarPath); + unpack(tarPath, function() { + // Attempt to remove temporary file + try { + fs.unlinkSync(tarPath); + } catch (err) {} + }); }); var options = { url: distBaseUrl + tarFilename diff --git a/docs/changelog.md b/docs/changelog.md index 86069b98..bfe8360d 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -16,6 +16,10 @@ [#326](https://github.com/lovell/sharp/issues/326) [@c0decafe](https://github.com/c0decafe) +* Attempt to remove temporary file after installation. + [#331](https://github.com/lovell/sharp/issues/331) + [@dtoubelis](https://github.com/dtoubelis) + #### v0.12.1 - 12th December 2015 * Allow use of SIMD vector instructions (via liborc) to be toggled on/off.