| 1 | /* |
| 2 | * Copyright (c) 2023. |
| 3 | * |
| 4 | * This software is free software; You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license |
| 5 | */ |
| 6 | |
| 7 | //! An incredibly spiffy deflate decoder. |
| 8 | //! |
| 9 | //! This crate features a deflate/zlib decoder inspired by |
| 10 | //! Eric Bigger's [libdeflate]. |
| 11 | //! |
| 12 | //! This libary has a smaller set of features hence you should use it |
| 13 | //! if it aligns with your end goals. |
| 14 | //! |
| 15 | //! Use it if |
| 16 | //! - You want a smaller library footprint when compared to flate/miniz-oxide |
| 17 | //! - You want faster speeds than zlib-ng/zlib/miniz-oxide. |
| 18 | //! - You do full buffer decompression and not streaming decompression. |
| 19 | //! - You don't need compression support for now, it will come soon enough. |
| 20 | //! - You want a 100% safe, pure rust implementation with above. |
| 21 | //! |
| 22 | //!Do not use it if |
| 23 | //! - You want compression support, not yet there |
| 24 | //! - You stream your data, not compatible with this library |
| 25 | //! |
| 26 | //! ## Alternatives |
| 27 | //!- For the fastest speeds, check out [libdeflate] (C), if using Rust there is [libdeflater] which |
| 28 | //! provides bindings to [libdeflate] |
| 29 | //! |
| 30 | //!- For streaming support use [flate2-rs] with an appropriate backend(zlib-ng is recommended for speed) |
| 31 | //! |
| 32 | //! # Features |
| 33 | //! You can disable features depending on what you need. the following are |
| 34 | //! features present |
| 35 | //! - gzip: Enable gzip decoding |
| 36 | //! - zlib: Enable zlib decoding |
| 37 | //! |
| 38 | //! These features are enabled by default |
| 39 | //! |
| 40 | //! To disable a feature , modify Cargo.toml to disable default features |
| 41 | //! and add the needed feature , e.g below will include zlib decoding and disable gzip decoding |
| 42 | //! ```toml |
| 43 | //! zune-inflate={ version="0.2",default-features=false,feature=["zlib"]} |
| 44 | //! ``` |
| 45 | //! |
| 46 | //! # Errors |
| 47 | //! In case of an error, the library returns the error and the decoded |
| 48 | //! data up to when the error was encountered hence that data can be recovered |
| 49 | //! but no data further than that can be recovered |
| 50 | //! |
| 51 | //! |
| 52 | //! # Usage |
| 53 | //! |
| 54 | //! Decoding delfate data |
| 55 | // |
| 56 | //! ```no_run |
| 57 | //! use zune_inflate::DeflateDecoder; |
| 58 | //! let totally_valid_data = [0;23]; |
| 59 | //! let mut decoder = DeflateDecoder::new(&totally_valid_data); |
| 60 | //! |
| 61 | //! let decompressed =decoder.decode_deflate().unwrap(); |
| 62 | //! ``` |
| 63 | //! |
| 64 | //! Decoding zlib data |
| 65 | //! ```no_run |
| 66 | //! use zune_inflate::DeflateDecoder; |
| 67 | //! // yea this isn't valid |
| 68 | //! let totally_valid_data = [0;23]; |
| 69 | //! let mut decoder = DeflateDecoder::new(&totally_valid_data); |
| 70 | //! |
| 71 | //! let decompressed =decoder.decode_zlib().unwrap(); |
| 72 | //! ``` |
| 73 | //! |
| 74 | //! Decoding zlib data without confirming the adler32 checksum |
| 75 | //! ```no_run |
| 76 | //! use zune_inflate::DeflateDecoder; |
| 77 | //! use zune_inflate::DeflateOptions; |
| 78 | //! let totally_valid_data=[0;23]; |
| 79 | //! let mut options = DeflateOptions::default() |
| 80 | //! .set_confirm_checksum(false); |
| 81 | //! let decoder = DeflateDecoder::new_with_options(&totally_valid_data,options); |
| 82 | //! |
| 83 | //! ``` |
| 84 | //! |
| 85 | //! [libdeflate]: https://github.com/ebiggers/libdeflate |
| 86 | //! [libdeflater]: https://github.com/adamkewley/libdeflater |
| 87 | //! [flate2-rs]: https://github.com/rust-lang/flate2-rs |
| 88 | //! |
| 89 | #![cfg_attr (not(feature = "std" ), no_std)] |
| 90 | extern crate alloc; |
| 91 | |
| 92 | pub use crate::decoder::{DeflateDecoder, DeflateOptions}; |
| 93 | pub use crate::encoder::DeflateEncoder; |
| 94 | |
| 95 | mod bitstream; |
| 96 | mod constants; |
| 97 | mod crc; |
| 98 | mod decoder; |
| 99 | mod encoder; |
| 100 | pub mod errors; |
| 101 | mod gzip_constants; |
| 102 | mod utils; |
| 103 | |