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

deflate implementation in standard library #213

Closed
andrewrk opened this issue Nov 9, 2016 · 19 comments
Closed

deflate implementation in standard library #213

andrewrk opened this issue Nov 9, 2016 · 19 comments
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. enhancement Solving this issue will likely involve adding new logic or components to the codebase. standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Nov 9, 2016

These compression and decompression functions are so common that we should have them ship with the compiler. We'll probably need to depend on them for the package manager.

@andrewrk andrewrk added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Nov 9, 2016
@itsmontoya
Copy link

Commenting here since Github won't let me be assigned.

I'll try to look into this asap

@andrewrk andrewrk added this to the 0.2.0 milestone May 7, 2017
@andrewrk andrewrk added the standard library This issue involves writing Zig code for the standard library. label Aug 27, 2017
@andrewrk andrewrk modified the milestones: 0.2.0, 0.3.0 Oct 20, 2017
@andrewrk andrewrk modified the milestones: 0.3.0, 0.4.0 Feb 28, 2018
@andrewrk andrewrk added the contributor friendly This issue is limited in scope and/or knowledge of Zig internals. label Nov 28, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Nov 28, 2018
@daurnimator
Copy link
Contributor

@itsmontoya @schmee did either of you get anywhere on this issue?

@devzero
Copy link

devzero commented May 4, 2019

I didn't write it, but I found this: https://github.com/tiehuis/zig-deflate that looks pretty far along

@emekoi
Copy link
Contributor

emekoi commented May 4, 2019

the implementation that is based on isn't designed for speed.

@schmee
Copy link
Contributor

schmee commented May 5, 2019

@daurnimator I'm messing around with it but no promises about when/if I'll be done. So if someone else wants to work on this please feel free! 🙂

@daurnimator
Copy link
Contributor

Once this is done it should be used so that we can store the glibc data compressed (see #2847 (comment) )

@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Aug 19, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Feb 10, 2020
@andrewrk
Copy link
Member Author

andrewrk commented Mar 1, 2020

This is a really nice article on the subject: https://www.hanshq.net/zip.html

@mlarouche
Copy link
Contributor

I'll writing one for PNG support in zigimg

@iamgreaser
Copy link

Currently working on an implementation myself. I've got decompression working (it's about 1/4 of the speed of gunzip although it doesn't write to an actual output file yet), and I started working on a compressor yesterday, although that hasn't been pushed yet.

https://github.com/iamgreaser/deflate-for-zig/

I can be found on #zig under the name GreaseMonkey, if you have any suggestions then let me know.

@mlarouche
Copy link
Contributor

My current progress is here: https://github.com/mlarouche/zigimg/blob/ReadPNGSupport/src/compression/deflate.zig Haven't mesured performance yet

@iamgreaser
Copy link

OK, so we've had 3 decompressors so far, of which the earlier one appears to be a port of a C implementation, and the other two happen to both work on Zig 0.6.0.

As far as performance is concerned, it'll really only be slow if you aren't buffering your input. If you're using the InStream interface, then you can plug in a BufferedInStream and that'll magically fix the worst of it.

If this should be in the standard library, then what API should we provide? And what primitives would we want in the standard library to make this work?

I'm mostly thinking from the perspective of

Here's what I'm thinking in terms of an API:

pub fn DeflateInStream(comptime TypeInStream: type) type { ... }
pub fn GzipInStream(comptime TypeInStream: type) type { ... } // FIXME: What capitalisation should we use?
pub fn ZlibInStream(comptime TypeInStream: type) type { ... }

And as for primitives, we do have BufferedInStream, BitInStream, and hash.Crc32 already (daurnimator pointed some of these out on IRC), but we're likely to need something like these to become a thing (names and interfaces TBD):

pub fn CanonicalHuffmanReader(... TODO ..., comptime out_type: type, max_len: usize) type { ... }
pub fn LzSlidingWindow(... TODO ..., comptime size: usize) type { ... }

Thoughts?

@mlarouche
Copy link
Contributor

Looks good to me :)

@Rocknest
Copy link
Contributor

Rocknest commented Sep 8, 2020

@andrewrk please reopen since DEFLATE is not yet implemented

@andrewrk
Copy link
Member Author

andrewrk commented Sep 8, 2020

std.compress.deflate.inflateStream

@andrewrk
Copy link
Member Author

andrewrk commented Sep 8, 2020

ahh I see, my mistake.

@andrewrk andrewrk reopened this Sep 8, 2020
@andrewrk andrewrk changed the title deflate, inflate implementation in standard library deflate implementation in standard library Sep 8, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 9, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@gsquire
Copy link
Contributor

gsquire commented Mar 17, 2021

Would you be interested in including a snappy encoder and decoder? I implemented the block format here. It needs some more tests and polish but it's in a working state as of now.

@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@marnix
Copy link

marnix commented Aug 4, 2021

Quoting iszn_11 from Discord:

I wrote a png decoder based on stb_image.h (basically a port), including zlib/deflate decompressor. While I could just use stb, I learned a lot about pngs and deflate. Honestly, png is the easy part. It's the decompression that almost broke me 🙃 .
https://gist.github.com/iszn11/4b4ae5cb68620fde295de4053e62d566

(Source: Discord link.)

@hdorio
Copy link
Contributor

hdorio commented Jan 9, 2022

This is a really nice article on the subject: https://www.hanshq.net/zip.html

I made a Zig version of it if anyone wants to follow along with the article with Zig code https://github.com/hdorio/hwzip.zig

I also made a Zig version of the Go package compress/flate #10552

@andrewrk
Copy link
Member Author

Thanks @hdorio! Landed in 0c1df96.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. enhancement Solving this issue will likely involve adding new logic or components to the codebase. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests