Blame


1 2181e0c8 2019-03-19 stsp /*
2 2181e0c8 2019-03-19 stsp * Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
3 2181e0c8 2019-03-19 stsp *
4 2181e0c8 2019-03-19 stsp * Permission to use, copy, modify, and distribute this software for any
5 2181e0c8 2019-03-19 stsp * purpose with or without fee is hereby granted, provided that the above
6 2181e0c8 2019-03-19 stsp * copyright notice and this permission notice appear in all copies.
7 2181e0c8 2019-03-19 stsp *
8 2181e0c8 2019-03-19 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 2181e0c8 2019-03-19 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 2181e0c8 2019-03-19 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 2181e0c8 2019-03-19 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 2181e0c8 2019-03-19 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 2181e0c8 2019-03-19 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 2181e0c8 2019-03-19 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 2181e0c8 2019-03-19 stsp */
16 2181e0c8 2019-03-19 stsp
17 91b40e30 2021-05-21 stsp struct got_deflate_checksum {
18 91b40e30 2021-05-21 stsp /* If not NULL, mix output bytes into this CRC checksum. */
19 91b40e30 2021-05-21 stsp uint32_t *output_crc;
20 91b40e30 2021-05-21 stsp
21 b16893ba 2023-02-24 thomas /* If not NULL, mix output bytes into this hash context. */
22 b16893ba 2023-02-24 thomas struct got_hash *output_ctx;
23 91b40e30 2021-05-21 stsp };
24 91b40e30 2021-05-21 stsp
25 2181e0c8 2019-03-19 stsp struct got_deflate_buf {
26 2181e0c8 2019-03-19 stsp z_stream z;
27 dbaa2362 2021-09-28 thomas uint8_t *inbuf;
28 2181e0c8 2019-03-19 stsp size_t inlen;
29 dbaa2362 2021-09-28 thomas uint8_t *outbuf;
30 2181e0c8 2019-03-19 stsp size_t outlen;
31 2181e0c8 2019-03-19 stsp int flags;
32 2181e0c8 2019-03-19 stsp #define GOT_DEFLATE_F_HAVE_MORE 0x01
33 2181e0c8 2019-03-19 stsp #define GOT_DEFLATE_F_OWN_OUTBUF 0x02
34 2181e0c8 2019-03-19 stsp };
35 2181e0c8 2019-03-19 stsp
36 2181e0c8 2019-03-19 stsp #define GOT_DEFLATE_BUFSIZE 8192
37 2181e0c8 2019-03-19 stsp
38 2181e0c8 2019-03-19 stsp const struct got_error *got_deflate_init(struct got_deflate_buf *, uint8_t *,
39 3b9e6fcf 2021-06-05 stsp size_t);
40 2181e0c8 2019-03-19 stsp const struct got_error *got_deflate_read(struct got_deflate_buf *, FILE *,
41 e8f02263 2022-01-23 thomas off_t, size_t *, off_t *);
42 9249e7e3 2022-05-12 thomas const struct got_error *got_deflate_read_mmap(struct got_deflate_buf *,
43 9249e7e3 2022-05-12 thomas uint8_t *, size_t, size_t, size_t *, size_t *);
44 2181e0c8 2019-03-19 stsp void got_deflate_end(struct got_deflate_buf *);
45 20a7d452 2022-10-16 thomas const struct got_error *got_deflate_to_fd(off_t *, FILE *, off_t, int,
46 20a7d452 2022-10-16 thomas struct got_deflate_checksum *);
47 20a7d452 2022-10-16 thomas const struct got_error *got_deflate_to_fd_mmap(off_t *, uint8_t *,
48 20a7d452 2022-10-16 thomas size_t, size_t, int, struct got_deflate_checksum *);
49 e8f02263 2022-01-23 thomas const struct got_error *got_deflate_to_file(off_t *, FILE *, off_t, FILE *,
50 91b40e30 2021-05-21 stsp struct got_deflate_checksum *);
51 e8f02263 2022-01-23 thomas const struct got_error *got_deflate_to_file_mmap(off_t *, uint8_t *,
52 2b0ae357 2022-01-10 thomas size_t, size_t, FILE *, struct got_deflate_checksum *);
53 9249e7e3 2022-05-12 thomas const struct got_error *got_deflate_flush(struct got_deflate_buf *, FILE *,
54 9249e7e3 2022-05-12 thomas struct got_deflate_checksum *, off_t *);
55 9249e7e3 2022-05-12 thomas const struct got_error *got_deflate_append_to_file_mmap(
56 9249e7e3 2022-05-12 thomas struct got_deflate_buf *, off_t *, uint8_t *, size_t, size_t, FILE *,
57 9249e7e3 2022-05-12 thomas struct got_deflate_checksum *);
58 9249e7e3 2022-05-12 thomas const struct got_error *got_deflate_to_mem_mmap(uint8_t **, size_t *, size_t *,
59 9249e7e3 2022-05-12 thomas struct got_deflate_checksum *, uint8_t *, size_t, size_t);