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

API questions #125

Open
notcancername opened this issue Jun 2, 2023 · 3 comments
Open

API questions #125

notcancername opened this issue Jun 2, 2023 · 3 comments

Comments

@notcancername
Copy link
Contributor

notcancername commented Jun 2, 2023

  • Why is the interface to a codec done at runtime? All codecs need to be known at compile-time anyway.
  • Why does every format necessarily have encoding and decoding functions? Some formats don't have encoders.
  • Why are we still using StreamSource instead of Reader/Writer and SeekableStream despite the lack of buffering harming performance?
  • Why are there no dedicated functions to read headers?

A nicer API would probably do these. I'd love to attempt such a change if people are fine with it.

@mlarouche
Copy link
Collaborator

  1. By re-looking at the code, indeed it could be inlined at compile-time! For the reason why, well it was early in my Zig journey so C++-ism still prevailed.
  2. It is the intention to have encoder and decoder for each supported format.
  3. The reader/writer stream is a long story, the initial reason for using StreamSource was to have a single I/O interface for both file and memory buffers, we are also trying to get the standard library to have a buffered version of StreamSource, see Improved IO API around seeking ziglang/zig#14670, but the PR is stuck in the pile.
  4. Well because I didn't think of adding one, it could be helpful for fixing Get image metadata without loading the whole image #100

@notcancername
Copy link
Contributor Author

Thanks for the detailed answers!
Do you think replacing StreamSource with a pair of Reader and SeekableStream in the future would be beneficial? It would mean that users could implement buffering on their end (and Image.fromFile could do so as well, etc.)? The issue with that would be that the interface would have to be made comptime first. (unless we make runtime Reader and SeekableStream but that'd be overkill)

@igor84
Copy link
Collaborator

igor84 commented Jun 2, 2023

If that Zig pull request would be accepted I would gladly implement its usage here but I am still waiting and hoping :).

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