Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement streams as with node-canvas #963

Open
GreenFlag31 opened this issue Dec 8, 2024 · 2 comments
Open

Implement streams as with node-canvas #963

GreenFlag31 opened this issue Dec 8, 2024 · 2 comments
Assignees

Comments

@GreenFlag31
Copy link

Hi.

Your solution has been choosed as replacement for pdfjs-dist of node-canvas. However, it does not implement streams (nodejs) as with node canvas : see here.
Implementing streams improves memory consumption and is not slower according to my tests (tested to convert a PDF into an image with/without streams).

Would it be something you could consider?

@Brooooooklyn Brooooooklyn self-assigned this Dec 9, 2024
@santiq
Copy link

santiq commented Dec 12, 2024

I know its not technically the same, but I'm using this as a quick patch.


import { Readable } from 'stream';

import { createCanvas } from "@napi-rs/canvas";

const canvas = createCanvas(100, 100);

const canvasStream = Readable.from(canvas.toBuffer('image/png'));

@GreenFlag31
Copy link
Author

Yep, this is possible, but this is like paying 2 times to cost of rendering. canvas.toBuffer(...) already has a cost. If you wrap it inside a stream, it means paying 2 times to cost of rendering. The goal is to use a stream instead of canvas.toBuffer().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants