ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
33.62k stars 2.46k forks source link

std.compress: API cleanup for decompression across different formats #14739

Open dweiller opened 1 year ago

dweiller commented 1 year ago

Currently the different formats in std.compress have inconsistent APIs, which complicates writing code that is generic over different formats - the package manager makes use of identical APIs to make the unpackTarball() function generic over the format.

This issue is looking to gather ideas about how a common decompression API can be exposed for the different formats or decide that it's not worth it or not possible in a reasonable way. The status quo is:

I think that the names Decompress()/decompress() are not particularly clear on what they do, especially if non-streaming APIs are available (hence the choice to use DecompressStream/decompressStream for zstandard). I think including 'stream' in the name makes sense to make it clear that these are streaming APIs.

I'm not familiar with the details of the formats other than Zstandard, but does it make sense to move the initial fallible operations performed by initialisation into the read function for the others so all decompress() analogues can be non-fallible? I don't believe there is any fallible initialisation that makes sense for Zstandard and it seems silly to make the return type error{}!DecompressStream(...) just to match the others.

What level of detail is desired? zstandard exposes significantly more lower-level details than the other - enough that I think all the higher level entry points are written purely in terms of lower level functions/types that are exposed publicly. I like exposing these building blocks so that people who have a use-case where they want a more control over decompression can do it while reusing the code that std needs anyway, but maybe it's not worth the API complexity?

andrewrk commented 10 months ago

I think you've accurately identified the problem to be solved. Do you have a proposed solution? I think if you went through the trouble to open a PR to resolve this, it would likely be a satisfactory solution.