Skip to content

Commit

Permalink
fix: return Uint8ClampedArray instead of Buffer in generateImage func…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
gugu committed Jun 5, 2024
1 parent a318ec4 commit 46d32ac
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/png.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ export async function generateImage({
})
qrImage.composite(layers);
}
return await qrImage.png().toBuffer();
const { data } = await qrImage.png().toBuffer({ resolveWithObject: true});
return new Uint8ClampedArray(data.buffer);
}
6 changes: 6 additions & 0 deletions src/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ interface TestParams {
filename: "qr_with_logo.pdf",
params: { logo: await readFile(`${goldenDir}/logo.png`) },
},
{
name: "PNG memory usage",
fn: getPNG,
filename: "qr_large.png",
params: { size: 300, margin: 10 },
}
] as TestParams[]).forEach((testData) => {
test.serial(testData.name, async (t) => {
const image = await testData.fn(text, {
Expand Down
Binary file added test_data/golden/qr_large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 46d32ac

Please sign in to comment.