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 91b40e30 2021-05-21 stsp /* If not NULL, mix output bytes into this SHA1 context. */
22 91b40e30 2021-05-21 stsp SHA1_CTX *output_sha1;
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 2181e0c8 2019-03-19 stsp size_t *);
42 2181e0c8 2019-03-19 stsp void got_deflate_end(struct got_deflate_buf *);
43 91b40e30 2021-05-21 stsp const struct got_error *got_deflate_to_file(size_t *, FILE *, FILE *,
44 91b40e30 2021-05-21 stsp struct got_deflate_checksum *);