diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-18 13:37:38 +0200 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-18 13:37:38 +0200 |
commit | 9ef4abad615bea12d13be542b8ae5fbeb2dfee32 (patch) | |
tree | 8875a687e004d331c9ea6a1d511a328c72b88113 /src/util/compress.c | |
parent | e95236b3ed78cd597c15f34b89385295702b627f (diff) | |
download | gnunet-9ef4abad615bea12d13be542b8ae5fbeb2dfee32.tar.gz gnunet-9ef4abad615bea12d13be542b8ae5fbeb2dfee32.zip |
NEWS: Refactoring components under src/ into lib/, plugin/, cli/ and service/
This also includes a necessary API refactoring of crypto from IDENTITY
to UTIL.
Diffstat (limited to 'src/util/compress.c')
-rw-r--r-- | src/util/compress.c | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/src/util/compress.c b/src/util/compress.c deleted file mode 100644 index 73fa25bd9..000000000 --- a/src/util/compress.c +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2022 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file util/compress.c | ||
23 | * @brief Simple (de)compression logic | ||
24 | * @author Philipp Toelke | ||
25 | * @author Martin Schanzenbach | ||
26 | */ | ||
27 | |||
28 | #include "platform.h" | ||
29 | #include "gnunet_util_lib.h" | ||
30 | #include <zlib.h> | ||
31 | |||
32 | int | ||
33 | GNUNET_try_compression (const char *data, | ||
34 | size_t old_size, | ||
35 | char **result, | ||
36 | size_t *new_size) | ||
37 | { | ||
38 | char *tmp; | ||
39 | uLongf dlen; | ||
40 | |||
41 | *result = NULL; | ||
42 | *new_size = 0; | ||
43 | #ifdef compressBound | ||
44 | dlen = compressBound (old_size); | ||
45 | #else | ||
46 | dlen = old_size + (old_size / 100) + 20; | ||
47 | /* documentation says 100.1% oldSize + 12 bytes, but we | ||
48 | * should be able to overshoot by more to be safe */ | ||
49 | #endif | ||
50 | tmp = GNUNET_malloc (dlen); | ||
51 | if (Z_OK == | ||
52 | compress2 ((Bytef *) tmp, | ||
53 | &dlen, | ||
54 | (const Bytef *) data, | ||
55 | old_size, 9)) | ||
56 | { | ||
57 | if (dlen < old_size) | ||
58 | { | ||
59 | *result = tmp; | ||
60 | *new_size = dlen; | ||
61 | return GNUNET_YES; | ||
62 | } | ||
63 | } | ||
64 | GNUNET_free (tmp); | ||
65 | return GNUNET_NO; | ||
66 | } | ||
67 | |||
68 | |||
69 | char * | ||
70 | GNUNET_decompress (const char *input, | ||
71 | size_t input_size, | ||
72 | size_t output_size) | ||
73 | { | ||
74 | char *output; | ||
75 | uLongf olen; | ||
76 | |||
77 | olen = output_size; | ||
78 | output = GNUNET_malloc (olen); | ||
79 | if (Z_OK == | ||
80 | uncompress ((Bytef *) output, | ||
81 | &olen, | ||
82 | (const Bytef *) input, | ||
83 | input_size)) | ||
84 | return output; | ||
85 | GNUNET_free (output); | ||
86 | return NULL; | ||
87 | } | ||
88 | |||
89 | |||
90 | |||
91 | /* end of compress.c */ | ||