portable: include utf8d.h in dist tarball
[got-portable.git] / lib / got_lib_deltify.h
blob973f1682b45bdf0b31cfe37ef1473caa9819418d
1 /*
2 * Copyright (c) 2020 Ori Bernstein
3 * Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 struct got_delta_block {
19 off_t len;
20 off_t offset;
21 uint32_t hash;
24 struct got_delta_table {
25 struct got_delta_block *blocks;
26 int nblocks;
27 int nalloc;
30 * Index for blocks. offs[n] is zero when the slot is free,
31 * otherwise it points to blocks[offs[n] - 1].
33 uint32_t *offs;
34 int len;
35 int size;
38 struct got_delta_instruction {
39 int copy;
40 off_t offset;
41 off_t len;
44 enum {
45 GOT_DELTIFY_MINCHUNK = 32,
46 GOT_DELTIFY_MAXCHUNK = 8192,
47 GOT_DELTIFY_SPLITMASK = (1 << 8) - 1,
50 const struct got_error *got_deltify_init(struct got_delta_table **dt, FILE *f,
51 off_t fileoffset, off_t filesize, uint32_t seed);
52 const struct got_error *got_deltify_init_mem(struct got_delta_table **dt,
53 uint8_t *data, off_t fileoffset, off_t filesize, uint32_t seed);
54 const struct got_error *got_deltify(struct got_delta_instruction **deltas,
55 int *ndeltas, FILE *f, off_t fileoffset, off_t filesize, uint32_t seed,
56 struct got_delta_table *dt, FILE *basefile, off_t basefile_offset0,
57 off_t basefile_size);
58 const struct got_error *got_deltify_file_mem(
59 struct got_delta_instruction **deltas, int *ndeltas,
60 FILE *f, off_t fileoffset, off_t filesize, uint32_t seed,
61 struct got_delta_table *dt, uint8_t *basedata, off_t basefile_offset0,
62 off_t basefile_size);
63 const struct got_error *got_deltify_mem_file(
64 struct got_delta_instruction **deltas, int *ndeltas,
65 uint8_t *data, off_t fileoffset, off_t filesize, uint32_t seed,
66 struct got_delta_table *dt, FILE *basefile, off_t basefile_offset0,
67 off_t basefile_size);
68 const struct got_error *got_deltify_mem_mem(
69 struct got_delta_instruction **deltas, int *ndeltas,
70 uint8_t *data, off_t fileoffset, off_t filesize, uint32_t seed,
71 struct got_delta_table *dt, uint8_t *basedata, off_t basefile_offset0,
72 off_t basefile_size);
73 void got_deltify_free(struct got_delta_table *dt);