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 ae25a666 2023-02-23 op /* If not NULL, mix output bytes into this hash context. */
22 ae25a666 2023-02-23 op 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 31e61ec1 2021-09-28 naddy uint8_t *inbuf;
28 2181e0c8 2019-03-19 stsp size_t inlen;
29 31e61ec1 2021-09-28 naddy 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 72840534 2022-01-19 stsp off_t, size_t *, off_t *);
42 2d9e6abf 2022-05-04 stsp const struct got_error *got_deflate_read_mmap(struct got_deflate_buf *,
43 2d9e6abf 2022-05-04 stsp 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 894e4711 2022-10-15 stsp const struct got_error *got_deflate_to_fd(off_t *, FILE *, off_t, int,
46 894e4711 2022-10-15 stsp struct got_deflate_checksum *);
47 894e4711 2022-10-15 stsp const struct got_error *got_deflate_to_fd_mmap(off_t *, uint8_t *,
48 894e4711 2022-10-15 stsp size_t, size_t, int, struct got_deflate_checksum *);
49 72840534 2022-01-19 stsp 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 72840534 2022-01-19 stsp const struct got_error *got_deflate_to_file_mmap(off_t *, uint8_t *,
52 64a8571e 2022-01-07 stsp size_t, size_t, FILE *, struct got_deflate_checksum *);
53 2d9e6abf 2022-05-04 stsp const struct got_error *got_deflate_flush(struct got_deflate_buf *, FILE *,
54 2d9e6abf 2022-05-04 stsp struct got_deflate_checksum *, off_t *);
55 2d9e6abf 2022-05-04 stsp const struct got_error *got_deflate_append_to_file_mmap(
56 2d9e6abf 2022-05-04 stsp struct got_deflate_buf *, off_t *, uint8_t *, size_t, size_t, FILE *,
57 2d9e6abf 2022-05-04 stsp struct got_deflate_checksum *);
58 2d9e6abf 2022-05-04 stsp const struct got_error *got_deflate_to_mem_mmap(uint8_t **, size_t *, size_t *,
59 2d9e6abf 2022-05-04 stsp struct got_deflate_checksum *, uint8_t *, size_t, size_t);