diff --git a/src/views/img.js b/src/views/img.js index 926b914..db01892 100644 --- a/src/views/img.js +++ b/src/views/img.js @@ -34,7 +34,7 @@ const img = async (ctx, page, size) => { // dynamically set media type ctx.type = `image/${type}`; - ctx.body = image; + ctx.body = Buffer.from(image); }; module.exports = renderImgOrSvg(img); diff --git a/src/views/pdf.js b/src/views/pdf.js index 5c7531a..a653b92 100644 --- a/src/views/pdf.js +++ b/src/views/pdf.js @@ -63,7 +63,7 @@ const pdf = async (ctx, page, size) => { debug('printed to pdf, file size: %o', pdf.length); ctx.type = 'application/pdf'; - ctx.body = pdf; + ctx.body = Buffer.from(pdf); }; module.exports = renderImgOrSvg(pdf); diff --git a/test/kitchensink.test.js b/test/kitchensink.test.js index 471f0a2..b4f71ba 100644 --- a/test/kitchensink.test.js +++ b/test/kitchensink.test.js @@ -406,7 +406,7 @@ describe('app', () => { ); expect(resp.status).toEqual(200); expect(resp.type).toEqual('application/pdf'); - expect(resp.body.length).toBeGreaterThan(19 * KB); + expect(resp.body.length).toBeGreaterThan(17 * KB); await PDFDocument.load(resp.body.toString('base64')); }); @@ -417,7 +417,7 @@ describe('app', () => { ); expect(resp.status).toEqual(200); expect(resp.type).toEqual('application/pdf'); - expect(resp.body.length).toBeGreaterThan(19 * KB); + expect(resp.body.length).toBeGreaterThan(17 * KB); const pdfDoc = await PDFDocument.load(resp.body.toString('base64')); const pages = pdfDoc.getPages();