Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});