Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Stress a bit sharp to show memory leak
var sharp = require('sharp');
var async = require("async");
sharp.cache(0);
var dlImage = function(done) {
var http = require('http');
var fs = require('fs');
if(!fs.existsSync("fixture.jpg")) {
var file = fs.createWriteStream("fixture.jpg");
var request = http.get("http://anthropocenejournal.files.wordpress.com/2012/12/nasa-high-res-earth-at-night-dnb_land_ocean_ice-2012-13500x6750.jpg", function(response) {
response.pipe(file);
file.on('finish', function() {
file.close(done);
});
});
} else {
done();
}
};
var sizes = [];
for (var i = 200; i < 1000; i++) {
sizes.push(i);
};
var resize = function(done) {
async.eachLimit(sizes, 5,
function(item, next) {
sharp("fixture.jpg").resize(item).sharpen().webp(function(err, buffer) {
next(err);
});
},
function(err){
done(err);
}
);
};
async.series([
dlImage,
resize
], function(err) {
console.log("done");
if(err)
console.log(err);
});
setInterval(function() {
console.log(process.memoryUsage());
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.