| 1 | /* embeddable gzip decoder: Copyright (C) 2026 Kamila Szewczyk <k@iczelia.net> |
| 2 | * limine: Copyright (C) 2019-2026 Mintsuki and contributors. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * 1. Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #ifndef COMPRESS__GZIP_H__ |
| 27 | #define COMPRESS__GZIP_H__ |
| 28 | |
| 29 | #include <fs/file.h> |
| 30 | |
| 31 | /* Check if a file handle points to gzip-compressed data (0x1F 0x8B magic). */ |
| 32 | bool gzip_check(struct file_handle * fd); |
| 33 | |
| 34 | /* Wrap a gzip-compressed file handle in a decompressing layer. |
| 35 | * |
| 36 | * Returns a new file_handle whose read callback transparently |
| 37 | * decompresses the data. The returned handle takes ownership of |
| 38 | * `compressed` and will close it when itself is closed. |
| 39 | * |
| 40 | * NOTE: ->size on the returned handle is set to UINT64_MAX as a |
| 41 | * sentinel for "unknown". The gzip ISIZE trailer is decompressed-size |
| 42 | * mod 2^32 and is not parsed here. Callers must drive ->read until |
| 43 | * it returns 0 (end-of-stream) to discover the true size. |
| 44 | * |
| 45 | * Supports very fast sequential reads and random-access reads (with |
| 46 | * an implicit rewind + skip penalty inherent to the gzip format). |
| 47 | */ |
| 48 | struct file_handle * gzip_open(struct file_handle * compressed); |
| 49 | |
| 50 | #endif |