Attempt to remove temp file after install #331

This commit is contained in:
Lovell Fuller 2016-01-06 16:31:01 +00:00
parent a0e034a9e9
commit 0ffa1e72d0
2 changed files with 16 additions and 4 deletions

View File

@ -25,7 +25,7 @@ var isFile = function(file) {
return exists; return exists;
}; };
var unpack = function(tarPath) { var unpack = function(tarPath, done) {
var extractor = tar.Extract({ var extractor = tar.Extract({
path: __dirname path: __dirname
}); });
@ -34,6 +34,9 @@ var unpack = function(tarPath) {
if (!isFile(vipsHeaderPath)) { if (!isFile(vipsHeaderPath)) {
error('Could not unpack ' + tarPath); error('Could not unpack ' + tarPath);
} }
if (typeof done === 'function') {
done();
}
}); });
fs.createReadStream(tarPath).on('error', error) fs.createReadStream(tarPath).on('error', error)
.pipe(zlib.Unzip()) .pipe(zlib.Unzip())
@ -73,10 +76,15 @@ module.exports.download_vips = function() {
if (isFile(tarPath)) { if (isFile(tarPath)) {
unpack(tarPath); unpack(tarPath);
} else { } else {
// Download // Download to per-process temporary file
tarPath = path.join(tmp, tarFilename); tarPath = path.join(tmp, process.pid + '-' + tarFilename);
var tmpFile = fs.createWriteStream(tarPath).on('finish', function() { 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 = { var options = {
url: distBaseUrl + tarFilename url: distBaseUrl + tarFilename

View File

@ -16,6 +16,10 @@
[#326](https://github.com/lovell/sharp/issues/326) [#326](https://github.com/lovell/sharp/issues/326)
[@c0decafe](https://github.com/c0decafe) [@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 - 12<sup>th</sup> December 2015 #### v0.12.1 - 12<sup>th</sup> December 2015
* Allow use of SIMD vector instructions (via liborc) to be toggled on/off. * Allow use of SIMD vector instructions (via liborc) to be toggled on/off.