diff --git a/src/image.js b/src/image.js index 66dc977..075518d 100644 --- a/src/image.js +++ b/src/image.js @@ -854,11 +854,26 @@ export default class Image { throw e; } } + }).then(results => { + // Strip buffers to free memory (only if file was written to disk) + if(results) { + for(let format in results) { + if(Array.isArray(results[format])) { + for(let stat of results[format]) { + if(stat.outputPath && stat.buffer && !this.options.dryRun) { + delete stat.buffer; + } + } + } + } + } + return results; }); return this.#queuePromise; } + // Factory to return from cache if available static create(src, options = {}) { let img = new Image(src, options); diff --git a/test/test.js b/test/test.js index 55d8688..cf6797d 100644 --- a/test/test.js +++ b/test/test.js @@ -1277,3 +1277,14 @@ test("#105 Transparent format output filtering (no minimum transparency formats // must include one of: svg, png, or gif t.deepEqual(Object.keys(stats), ["webp", "jpeg"]); }); + +test("Buffer should be stripped after writing to disk", async t => { + let stats = await eleventyImage("./test/bio-2017.jpg", { + formats: ["jpeg"], + outputDir: "./test/img/" + }); + + t.truthy(stats.jpeg[0].width); + t.truthy(stats.jpeg[0].outputPath); + t.falsy(stats.jpeg[0].buffer); +});