@based/db 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v24.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v25.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
- package/dist/lib/linux_aarch64/include/cdefs.h +324 -0
- package/dist/lib/linux_aarch64/include/jemalloc.h +468 -0
- package/dist/lib/linux_aarch64/include/libdeflate.h +345 -0
- package/dist/lib/linux_aarch64/include/libdeflate_strings.h +35 -0
- package/dist/lib/linux_aarch64/include/linker_set.h +109 -0
- package/dist/lib/linux_aarch64/include/queue.h +627 -0
- package/dist/lib/linux_aarch64/include/selva/_export.h +7 -0
- package/dist/lib/linux_aarch64/include/selva/align.h +9 -0
- package/dist/lib/linux_aarch64/include/selva/backoff_timeout.h +29 -0
- package/dist/lib/linux_aarch64/include/selva/bitmap.h +95 -0
- package/dist/lib/linux_aarch64/include/selva/colvec.h +71 -0
- package/dist/lib/linux_aarch64/include/selva/crc32c.h +17 -0
- package/dist/lib/linux_aarch64/include/selva/ctime.h +135 -0
- package/dist/lib/linux_aarch64/include/selva/db.h +450 -0
- package/dist/lib/linux_aarch64/include/selva/endian.h +301 -0
- package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +27 -0
- package/dist/lib/linux_aarch64/include/selva/fast_memcmp.h +18 -0
- package/dist/lib/linux_aarch64/include/selva/fast_memmem.h +11 -0
- package/dist/lib/linux_aarch64/include/selva/fast_parsei.h +36 -0
- package/dist/lib/linux_aarch64/include/selva/fields.h +341 -0
- package/dist/lib/linux_aarch64/include/selva/gmtime.h +137 -0
- package/dist/lib/linux_aarch64/include/selva/hll.h +85 -0
- package/dist/lib/linux_aarch64/include/selva/lpf.h +28 -0
- package/dist/lib/linux_aarch64/include/selva/mblen.h +40 -0
- package/dist/lib/linux_aarch64/include/selva/membar.h +32 -0
- package/dist/lib/linux_aarch64/include/selva/node_id_set.h +43 -0
- package/dist/lib/linux_aarch64/include/selva/poptop.h +114 -0
- package/dist/lib/linux_aarch64/include/selva/selva_hash128.h +49 -0
- package/dist/lib/linux_aarch64/include/selva/selva_lang.h +112 -0
- package/dist/lib/linux_aarch64/include/selva/selva_math.h +37 -0
- package/dist/lib/linux_aarch64/include/selva/selva_string.h +683 -0
- package/dist/lib/linux_aarch64/include/selva/sort.h +140 -0
- package/dist/lib/linux_aarch64/include/selva/strsearch.h +43 -0
- package/dist/lib/linux_aarch64/include/selva/thread.h +37 -0
- package/dist/lib/linux_aarch64/include/selva/timestamp.h +25 -0
- package/dist/lib/linux_aarch64/include/selva/types.h +115 -0
- package/dist/lib/linux_aarch64/include/selva/vector.h +35 -0
- package/dist/lib/linux_aarch64/include/selva_error.h +140 -0
- package/dist/lib/linux_aarch64/include/selva_lang_code.h +160 -0
- package/dist/lib/linux_aarch64/include/tree.h +852 -0
- package/dist/lib/linux_aarch64/libdeflate.so +0 -0
- package/dist/lib/linux_aarch64/libjemalloc_selva.so.2 +0 -0
- package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v24.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v25.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +0 -0
- package/dist/lib/linux_aarch64/libxxhash.so.0 +0 -0
- package/dist/lib/linux_x86_64/include/cdefs.h +324 -0
- package/dist/lib/linux_x86_64/include/jemalloc.h +468 -0
- package/dist/lib/linux_x86_64/include/libdeflate.h +345 -0
- package/dist/lib/linux_x86_64/include/libdeflate_strings.h +35 -0
- package/dist/lib/linux_x86_64/include/linker_set.h +109 -0
- package/dist/lib/linux_x86_64/include/queue.h +627 -0
- package/dist/lib/linux_x86_64/include/selva/_export.h +7 -0
- package/dist/lib/linux_x86_64/include/selva/align.h +9 -0
- package/dist/lib/linux_x86_64/include/selva/backoff_timeout.h +29 -0
- package/dist/lib/linux_x86_64/include/selva/bitmap.h +95 -0
- package/dist/lib/linux_x86_64/include/selva/colvec.h +71 -0
- package/dist/lib/linux_x86_64/include/selva/crc32c.h +17 -0
- package/dist/lib/linux_x86_64/include/selva/ctime.h +135 -0
- package/dist/lib/linux_x86_64/include/selva/db.h +450 -0
- package/dist/lib/linux_x86_64/include/selva/endian.h +301 -0
- package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +27 -0
- package/dist/lib/linux_x86_64/include/selva/fast_memcmp.h +18 -0
- package/dist/lib/linux_x86_64/include/selva/fast_memmem.h +11 -0
- package/dist/lib/linux_x86_64/include/selva/fast_parsei.h +36 -0
- package/dist/lib/linux_x86_64/include/selva/fields.h +341 -0
- package/dist/lib/linux_x86_64/include/selva/gmtime.h +137 -0
- package/dist/lib/linux_x86_64/include/selva/hll.h +85 -0
- package/dist/lib/linux_x86_64/include/selva/lpf.h +28 -0
- package/dist/lib/linux_x86_64/include/selva/mblen.h +40 -0
- package/dist/lib/linux_x86_64/include/selva/membar.h +32 -0
- package/dist/lib/linux_x86_64/include/selva/node_id_set.h +43 -0
- package/dist/lib/linux_x86_64/include/selva/poptop.h +114 -0
- package/dist/lib/linux_x86_64/include/selva/selva_hash128.h +49 -0
- package/dist/lib/linux_x86_64/include/selva/selva_lang.h +112 -0
- package/dist/lib/linux_x86_64/include/selva/selva_math.h +37 -0
- package/dist/lib/linux_x86_64/include/selva/selva_string.h +683 -0
- package/dist/lib/linux_x86_64/include/selva/sort.h +140 -0
- package/dist/lib/linux_x86_64/include/selva/strsearch.h +43 -0
- package/dist/lib/linux_x86_64/include/selva/thread.h +37 -0
- package/dist/lib/linux_x86_64/include/selva/timestamp.h +25 -0
- package/dist/lib/linux_x86_64/include/selva/types.h +115 -0
- package/dist/lib/linux_x86_64/include/selva/vector.h +35 -0
- package/dist/lib/linux_x86_64/include/selva_error.h +140 -0
- package/dist/lib/linux_x86_64/include/selva_lang_code.h +160 -0
- package/dist/lib/linux_x86_64/include/tree.h +852 -0
- package/dist/lib/linux_x86_64/libdeflate.so +0 -0
- package/dist/lib/linux_x86_64/libjemalloc_selva.so.2 +0 -0
- package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v24.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v25.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/lib/linux_x86_64/libxxhash.so.0 +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* libdeflate.h - public header for libdeflate
|
|
3
|
+
* Copyright (c) 2024 SAULX
|
|
4
|
+
* Copyright 2023 housisong
|
|
5
|
+
* Copyright 2016 Eric Biggers
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#ifndef LIBDEFLATE_H
|
|
11
|
+
#define LIBDEFLATE_H
|
|
12
|
+
|
|
13
|
+
#define LIBDEFLATE_VERSION_MAJOR 2
|
|
14
|
+
#define LIBDEFLATE_VERSION_MINOR 0
|
|
15
|
+
#define LIBDEFLATE_VERSION_STRING "2.0"
|
|
16
|
+
|
|
17
|
+
#include <stddef.h>
|
|
18
|
+
#include <stdint.h>
|
|
19
|
+
|
|
20
|
+
#ifndef LIBDEFLATEEXPORT
|
|
21
|
+
#ifdef BUILDING_LIBDEFLATE
|
|
22
|
+
#define LIBDEFLATEEXPORT __attribute__((visibility("default")))
|
|
23
|
+
#else
|
|
24
|
+
#define LIBDEFLATEEXPORT
|
|
25
|
+
#endif
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
/* ========================================================================== */
|
|
29
|
+
/* Compression */
|
|
30
|
+
/* ========================================================================== */
|
|
31
|
+
|
|
32
|
+
struct libdeflate_compressor;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* libdeflate_alloc_compressor() allocates a new compressor.
|
|
36
|
+
* 'compression_level' is the compression level on a zlib-like scale but with a
|
|
37
|
+
* higher maximum value (1 = fastest, 6 = medium/default, 9 = slow, 12 = slowest).
|
|
38
|
+
* Level 0 is also supported and means "no compression", specifically "create a
|
|
39
|
+
* valid stream, but only emit uncompressed blocks" (this will expand the data
|
|
40
|
+
* slightly).
|
|
41
|
+
*
|
|
42
|
+
* The return value is a pointer to the new compressor, or NULL if out of memory
|
|
43
|
+
* or if the compression level is invalid (i.e. outside the range [0, 12]).
|
|
44
|
+
*
|
|
45
|
+
* Note: for compression, the sliding window size is defined at compilation time
|
|
46
|
+
* to 32768, the largest size permissible in the DEFLATE format. It cannot be
|
|
47
|
+
* changed at runtime.
|
|
48
|
+
*
|
|
49
|
+
* A single compressor is not safe to use by multiple threads concurrently.
|
|
50
|
+
* However, different threads may use different compressors concurrently.
|
|
51
|
+
*/
|
|
52
|
+
LIBDEFLATEEXPORT struct libdeflate_compressor *
|
|
53
|
+
libdeflate_alloc_compressor(int compression_level);
|
|
54
|
+
|
|
55
|
+
LIBDEFLATEEXPORT struct libdeflate_compressor *
|
|
56
|
+
libdeflate_alloc_compressor2(int compression_level, const void *shared_dict);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* libdeflate_compress() performs raw DEFLATE compression on a buffer of
|
|
60
|
+
* data. The function attempts to compress 'in_nbytes' bytes of data located at
|
|
61
|
+
* 'in' and write the results to 'out', which has space for 'out_nbytes_avail'
|
|
62
|
+
* bytes. The return value is the compressed size in bytes, or 0 if the data
|
|
63
|
+
* could not be compressed to 'out_nbytes_avail' bytes or fewer.
|
|
64
|
+
*/
|
|
65
|
+
LIBDEFLATEEXPORT size_t
|
|
66
|
+
libdeflate_compress(struct libdeflate_compressor *compressor,
|
|
67
|
+
const void *in, size_t in_nbytes,
|
|
68
|
+
void *out, size_t out_nbytes_avail);
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* libdeflate_compress_bound() returns a worst-case upper bound on the
|
|
72
|
+
* number of bytes of compressed data that may be produced by compressing any
|
|
73
|
+
* buffer of length less than or equal to 'in_nbytes' using
|
|
74
|
+
* libdeflate_compress() with the specified compressor. Mathematically,
|
|
75
|
+
* this bound will necessarily be a number greater than or equal to 'in_nbytes'.
|
|
76
|
+
* It may be an overestimate of the true upper bound. The return value is
|
|
77
|
+
* guaranteed to be the same for all invocations with the same compressor and
|
|
78
|
+
* same 'in_nbytes'.
|
|
79
|
+
*
|
|
80
|
+
* Note that this function is not necessary in many applications. With
|
|
81
|
+
* block-based compression, it is usually preferable to separately store the
|
|
82
|
+
* uncompressed size of each block and to store any blocks that did not compress
|
|
83
|
+
* to less than their original size uncompressed. In that scenario, there is no
|
|
84
|
+
* need to know the worst-case compressed size, since the maximum number of
|
|
85
|
+
* bytes of compressed data that may be used would always be one less than the
|
|
86
|
+
* input length. You can just pass a buffer of that size to
|
|
87
|
+
* libdeflate_compress() and store the data uncompressed if
|
|
88
|
+
* libdeflate_compress() returns 0, indicating that the compressed data
|
|
89
|
+
* did not fit into the provided output buffer.
|
|
90
|
+
*/
|
|
91
|
+
LIBDEFLATEEXPORT size_t
|
|
92
|
+
libdeflate_compress_bound(size_t in_nbytes);
|
|
93
|
+
|
|
94
|
+
static inline size_t
|
|
95
|
+
libdeflate_compress_bound_block(size_t in_block_nbytes)
|
|
96
|
+
{
|
|
97
|
+
return libdeflate_compress_bound(in_block_nbytes) + 5;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* libdeflate_free_compressor() frees a compressor that was allocated with
|
|
102
|
+
* libdeflate_alloc_compressor().
|
|
103
|
+
* If a NULL pointer is passed in, no action is taken.
|
|
104
|
+
*/
|
|
105
|
+
LIBDEFLATEEXPORT void
|
|
106
|
+
libdeflate_free_compressor(struct libdeflate_compressor *compressor);
|
|
107
|
+
|
|
108
|
+
/* ========================================================================== */
|
|
109
|
+
/* Decompression */
|
|
110
|
+
/* ========================================================================== */
|
|
111
|
+
|
|
112
|
+
struct libdeflate_decompressor;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* libdeflate_alloc_decompressor() allocates a new decompressor.
|
|
116
|
+
* The return value is a pointer to
|
|
117
|
+
* the new decompressor, or NULL if out of memory.
|
|
118
|
+
*
|
|
119
|
+
* This function takes no parameters, and the returned decompressor is valid for
|
|
120
|
+
* decompressing data that was compressed at any compression level and with any
|
|
121
|
+
* sliding window size.
|
|
122
|
+
*
|
|
123
|
+
* A single decompressor is not safe to use by multiple threads concurrently.
|
|
124
|
+
* However, different threads may use different decompressors concurrently.
|
|
125
|
+
*/
|
|
126
|
+
LIBDEFLATEEXPORT struct libdeflate_decompressor *
|
|
127
|
+
libdeflate_alloc_decompressor(void);
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Result of a call to libdeflate_decompress().
|
|
131
|
+
*/
|
|
132
|
+
enum libdeflate_result {
|
|
133
|
+
/**
|
|
134
|
+
* Decompression was successful.
|
|
135
|
+
*/
|
|
136
|
+
LIBDEFLATE_SUCCESS = 0,
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Decompressed failed because the compressed data was invalid, corrupt,
|
|
140
|
+
* or otherwise unsupported.
|
|
141
|
+
*/
|
|
142
|
+
LIBDEFLATE_BAD_DATA = 1,
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* A NULL 'actual_out_nbytes_ret' was provided, but the data would have
|
|
146
|
+
* decompressed to fewer than 'out_nbytes_avail' bytes.
|
|
147
|
+
*/
|
|
148
|
+
LIBDEFLATE_SHORT_OUTPUT = 2,
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* The data would have decompressed to more than 'out_nbytes_avail'
|
|
152
|
+
* bytes.
|
|
153
|
+
*/
|
|
154
|
+
LIBDEFLATE_INSUFFICIENT_SPACE = 3,
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* More blocks availbled for decompression.
|
|
158
|
+
* Only returned by libdeflate_decompress_block().
|
|
159
|
+
*/
|
|
160
|
+
LIBDEFLATE_MORE = 4,
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* libdeflate_decompress() decompresses the DEFLATE-compressed stream
|
|
165
|
+
* from the buffer 'in' with compressed size up to 'in_nbytes' bytes.
|
|
166
|
+
* The uncompressed data is written to 'out', a buffer with size 'out_nbytes_avail'
|
|
167
|
+
* bytes. If decompression succeeds, then 0 (LIBDEFLATE_SUCCESS) is returned.
|
|
168
|
+
* Otherwise, a nonzero result code such as LIBDEFLATE_BAD_DATA is returned. If
|
|
169
|
+
* a nonzero result code is returned, then the contents of the output buffer are
|
|
170
|
+
* undefined.
|
|
171
|
+
*
|
|
172
|
+
* Decompression stops at the end of the DEFLATE stream (as indicated by the
|
|
173
|
+
* BFINAL flag), even if it is actually shorter than 'in_nbytes' bytes.
|
|
174
|
+
*
|
|
175
|
+
* libdeflate_decompress() can be used in cases where the actual
|
|
176
|
+
* uncompressed size is known (recommended) or unknown (not recommended):
|
|
177
|
+
*
|
|
178
|
+
* - If the actual uncompressed size is known, then pass the actual
|
|
179
|
+
* uncompressed size as 'out_nbytes_avail' and pass NULL for
|
|
180
|
+
* 'actual_out_nbytes_ret'. This makes libdeflate_decompress() fail
|
|
181
|
+
* with LIBDEFLATE_SHORT_OUTPUT if the data decompressed to fewer than the
|
|
182
|
+
* specified number of bytes.
|
|
183
|
+
*
|
|
184
|
+
* - If the actual uncompressed size is unknown, then provide a non-NULL
|
|
185
|
+
* 'actual_out_nbytes_ret' and provide a buffer with some size
|
|
186
|
+
* 'out_nbytes_avail' that you think is large enough to hold all the
|
|
187
|
+
* uncompressed data. In this case, if the data decompresses to less than
|
|
188
|
+
* or equal to 'out_nbytes_avail' bytes, then
|
|
189
|
+
* libdeflate_decompress() will write the actual uncompressed size
|
|
190
|
+
* to *actual_out_nbytes_ret and return 0 (LIBDEFLATE_SUCCESS). Otherwise,
|
|
191
|
+
* it will return LIBDEFLATE_INSUFFICIENT_SPACE if the provided buffer was
|
|
192
|
+
* not large enough but no other problems were encountered, or another
|
|
193
|
+
* nonzero result code if decompression failed for another reason.
|
|
194
|
+
*/
|
|
195
|
+
LIBDEFLATEEXPORT enum libdeflate_result
|
|
196
|
+
libdeflate_decompress(struct libdeflate_decompressor *decompressor,
|
|
197
|
+
const void *in, size_t in_nbytes,
|
|
198
|
+
void *out, size_t out_nbytes_avail,
|
|
199
|
+
size_t *actual_out_nbytes_ret);
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Like libdeflate_decompress(), but adds the 'actual_in_nbytes_ret'
|
|
203
|
+
* argument.
|
|
204
|
+
* If decompression succeeds and 'actual_in_nbytes_ret' is not NULL,
|
|
205
|
+
* then the actual compressed size of the DEFLATE stream (aligned to the next
|
|
206
|
+
* byte boundary) is written to *actual_in_nbytes_ret.
|
|
207
|
+
*/
|
|
208
|
+
LIBDEFLATEEXPORT enum libdeflate_result
|
|
209
|
+
libdeflate_decompress_ex(struct libdeflate_decompressor *decompressor,
|
|
210
|
+
const void *in, size_t in_nbytes,
|
|
211
|
+
void *out, size_t out_nbytes_avail,
|
|
212
|
+
size_t *actual_in_nbytes_ret,
|
|
213
|
+
size_t *actual_out_nbytes_ret);
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Decompress a small number of bytes into out.
|
|
217
|
+
* The size of the output buffer doesn't need to align with the block size of
|
|
218
|
+
* the compressed input, unlike with the block decompression API. The downside
|
|
219
|
+
* of this decompression function is that it's much slower for longer output
|
|
220
|
+
* sizes. However, it can be much faster to use this function to extract a
|
|
221
|
+
* small number of bytes (e.g. 16 bytes) rather than decompressing a full block
|
|
222
|
+
* and then extracting a few bytes from it. This is interesting also because a
|
|
223
|
+
* deflate block can be at least theoretically be extremely long, and they
|
|
224
|
+
* are typically >= 1kB in size in the wild. Whereas, with this function the
|
|
225
|
+
* output buffer can be even fitted in the stack as it's small and it's size
|
|
226
|
+
* can be hard-coded.
|
|
227
|
+
* @param in is a pointer to the compressed data.
|
|
228
|
+
* @param in_nbytes is the size of in.
|
|
229
|
+
* @param out_nbytes_avail is the size of the out buffer.
|
|
230
|
+
* @param actual_out_nbytes_ret returns the actual number of bytes decompressed.
|
|
231
|
+
*/
|
|
232
|
+
LIBDEFLATEEXPORT enum libdeflate_result
|
|
233
|
+
libdeflate_decompress_short(struct libdeflate_decompressor *decompressor,
|
|
234
|
+
const void *in, size_t in_nbytes,
|
|
235
|
+
void *out, size_t out_nbytes_avail,
|
|
236
|
+
size_t *actual_out_nbytes_ret);
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* ctrl libdeflate_decompress_block() stop condition
|
|
240
|
+
*/
|
|
241
|
+
enum libdeflate_decompress_stop_by {
|
|
242
|
+
LIBDEFLATE_STOP_BY_FINAL_BLOCK = 0,
|
|
243
|
+
LIBDEFLATE_STOP_BY_ANY_BLOCK = 1,
|
|
244
|
+
LIBDEFLATE_STOP_BY_ANY_BLOCK_AND_FULL_INPUT = 2,
|
|
245
|
+
LIBDEFLATE_STOP_BY_ANY_BLOCK_AND_FULL_OUTPUT = 3,
|
|
246
|
+
LIBDEFLATE_STOP_BY_ANY_BLOCK_AND_FULL_OUTPUT_AND_IN_BYTE_ALIGN = 4,
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Decompress a DEFLATE block.
|
|
251
|
+
* Large stream data can be decompress by calling libdeflate_decompress_block()
|
|
252
|
+
* multiple times. Each time call this function, 'out_block_with_in_dict' have
|
|
253
|
+
* 'in_dict_nbytes' repeat of the last called's tail outputted uncompressed data
|
|
254
|
+
* as dictionary data, and 'out_block_nbytes' new uncompressed data want be
|
|
255
|
+
* decompressed;
|
|
256
|
+
* The dictionary data size in_dict_nbytes<=32k, if it is greater than 32k, the extra
|
|
257
|
+
* part of the previous part of the dictionary data is invalid.
|
|
258
|
+
* libdeflate_compress_bound_block(out_block_nbytes) can get the upper limit
|
|
259
|
+
* of 'in_part' required space 'in_part_nbytes_bound'.
|
|
260
|
+
* 'is_final_block_ret' can be NULL.
|
|
261
|
+
*
|
|
262
|
+
* WARNING: This function must decompressed one full DEFLATE block before stop;
|
|
263
|
+
* so 'in_part_nbytes_bound' must possess a block end flag, and "out_block_nbytes"
|
|
264
|
+
* must be able to store uncompressed data of this block decompressed;
|
|
265
|
+
* This feature is not compatible with the DEFLATE stream decoding standard,
|
|
266
|
+
* this function can't support a single DEFLATE block that may have any length.
|
|
267
|
+
*/
|
|
268
|
+
LIBDEFLATEEXPORT enum libdeflate_result
|
|
269
|
+
libdeflate_decompress_block(struct libdeflate_decompressor *decompressor,
|
|
270
|
+
const void *in_part, size_t in_part_nbytes_bound,
|
|
271
|
+
void *out_block_with_in_dict, size_t in_dict_nbytes, size_t out_block_nbytes,
|
|
272
|
+
size_t *actual_in_nbytes_ret, size_t *actual_out_nbytes_ret,
|
|
273
|
+
enum libdeflate_decompress_stop_by stop_type);
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Clear the block decompressor save state.
|
|
277
|
+
* Clear the state saved between calls libdeflate_decompress_block();
|
|
278
|
+
* if you know the next block does not depend on the inputted data of the previous
|
|
279
|
+
* block, you can call this function reset 'decompressor';
|
|
280
|
+
* Note: if next block depend on the inputted data of the previous block, reset will
|
|
281
|
+
* cause libdeflate_decompress_block() to fail.
|
|
282
|
+
*/
|
|
283
|
+
LIBDEFLATEEXPORT void
|
|
284
|
+
libdeflate_decompress_block_reset(struct libdeflate_decompressor *decompressor);
|
|
285
|
+
|
|
286
|
+
struct libdeflate_block_state {
|
|
287
|
+
size_t cur_block_size;
|
|
288
|
+
size_t data_cur;
|
|
289
|
+
size_t out_cur;
|
|
290
|
+
size_t data_buf_size;
|
|
291
|
+
uint8_t *data_buf;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Initialize a block state struct.
|
|
296
|
+
* struct libdeflate_block_state is used with libdeflate_decompress_stream().
|
|
297
|
+
*/
|
|
298
|
+
LIBDEFLATEEXPORT struct libdeflate_block_state
|
|
299
|
+
libdeflate_block_state_init(size_t max_block_size);
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Increase the buffer size in a struct libdeflate_block_state.
|
|
303
|
+
* This function should be called if libdeflate_decompress_stream() returns with
|
|
304
|
+
* LIBDEFLATE_INSUFFICIENT_SPACE. Decompression should be retried only if this
|
|
305
|
+
* function returns `true`.
|
|
306
|
+
* @return value `true` if a larger buffer was allocated;
|
|
307
|
+
* `false` if the buffer wasn't changed.
|
|
308
|
+
*/
|
|
309
|
+
LIBDEFLATEEXPORT bool
|
|
310
|
+
libdeflate_block_state_growbuf(struct libdeflate_block_state *state);
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Deinitialize struct libdeflate_block_state.
|
|
314
|
+
* This frees data_buf.
|
|
315
|
+
*/
|
|
316
|
+
LIBDEFLATEEXPORT void
|
|
317
|
+
libdeflate_block_state_deinit(struct libdeflate_block_state *state);
|
|
318
|
+
|
|
319
|
+
typedef int (*libdeflate_decompress_stream_cb_t)(void * ctx, const uint8_t * buf, size_t dict_len, size_t data_len);
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Decompress deflated string in_buf block by block.
|
|
323
|
+
* Call libdeflate_block_state_init() before and libdeflate_block_state_deinit() after.
|
|
324
|
+
* @param cb is a callback that will be called for each decompressed block.
|
|
325
|
+
* Decompression is interrupted if the callback returns a non-zero value.
|
|
326
|
+
* @param result returns the non-zero return value of cb.
|
|
327
|
+
*/
|
|
328
|
+
LIBDEFLATEEXPORT enum libdeflate_result
|
|
329
|
+
libdeflate_decompress_stream(
|
|
330
|
+
struct libdeflate_decompressor *decompressor,
|
|
331
|
+
struct libdeflate_block_state *state,
|
|
332
|
+
const char *in_buf, size_t in_len,
|
|
333
|
+
libdeflate_decompress_stream_cb_t cb, void *ctx,
|
|
334
|
+
int *result);
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Free a decompressor.
|
|
338
|
+
* libdeflate_free_decompressor() frees a decompressor that was allocated with
|
|
339
|
+
* libdeflate_alloc_decompressor(). If a NULL pointer is passed in, no action
|
|
340
|
+
* is taken.
|
|
341
|
+
*/
|
|
342
|
+
LIBDEFLATEEXPORT void
|
|
343
|
+
libdeflate_free_decompressor(struct libdeflate_decompressor *decompressor);
|
|
344
|
+
|
|
345
|
+
#endif /* LIBDEFLATE_H */
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 SAULX
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include <stddef.h>
|
|
8
|
+
#include <stdint.h>
|
|
9
|
+
|
|
10
|
+
#ifndef LIBDEFLATEEXPORT
|
|
11
|
+
#ifdef BUILDING_LIBDEFLATE
|
|
12
|
+
#define LIBDEFLATEEXPORT __attribute__((visibility("default")))
|
|
13
|
+
#else
|
|
14
|
+
#define LIBDEFLATEEXPORT
|
|
15
|
+
#endif
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
struct libdeflate_block_state;
|
|
19
|
+
struct libdeflate_decompressor;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Test if the compressed string in_buf is equivalent to the buffer poited by ptr2_buf.
|
|
23
|
+
* First string deflated and second not
|
|
24
|
+
* @return Same as memcmp().
|
|
25
|
+
*/
|
|
26
|
+
LIBDEFLATEEXPORT int
|
|
27
|
+
libdeflate_memcmp(struct libdeflate_decompressor *decompressor, struct libdeflate_block_state *state, const char *in_buf, size_t in_len, const void *ptr2_buf, size_t ptr2_len);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Test if the compressed string in_buf includes the string needle_buf.
|
|
31
|
+
* First string deflated and second not
|
|
32
|
+
* @return Same as memmem().
|
|
33
|
+
*/
|
|
34
|
+
LIBDEFLATEEXPORT int64_t
|
|
35
|
+
libdeflate_memmem(struct libdeflate_decompressor *decompressor, struct libdeflate_block_state *state, const char *in_buf, size_t in_len, const void *needle_buf, size_t needle_len);
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*******************************************************************************
|
|
3
|
+
* @file linker_set.h
|
|
4
|
+
* @author Olli Vanhoja
|
|
5
|
+
*
|
|
6
|
+
* @brief Linker sets.
|
|
7
|
+
* @section LICENSE
|
|
8
|
+
* Copyright (c) 2020, 2023-2025 SAULX
|
|
9
|
+
* Copyright (c) 2018 Olli Vanhoja <olli.vanhoja@gmail.com>
|
|
10
|
+
* Copyright (c) 2015 Olli Vanhoja <olli.vanhoja@cs.helsinki.fi>
|
|
11
|
+
* Copyright (c) 1999 John D. Polstra
|
|
12
|
+
* Copyright (c) 1999,2001 Peter Wemm <peter@FreeBSD.org>
|
|
13
|
+
* All rights reserved.
|
|
14
|
+
*
|
|
15
|
+
* Redistribution and use in source and binary forms, with or without
|
|
16
|
+
* modification, are permitted provided that the following conditions
|
|
17
|
+
* are met:
|
|
18
|
+
* 1. Redistributions of source code must retain the above copyright
|
|
19
|
+
* notice, this list of conditions and the following disclaimer.
|
|
20
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
|
21
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
22
|
+
* documentation and/or other materials provided with the distribution.
|
|
23
|
+
*
|
|
24
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
25
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
26
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
27
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
28
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
29
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
30
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
31
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
32
|
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
33
|
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
34
|
+
* SUCH DAMAGE.
|
|
35
|
+
*
|
|
36
|
+
* SPDX-License-Identifier: BSD-2-Clause
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
#ifndef _SYS_LINKER_SET_H_
|
|
40
|
+
#define _SYS_LINKER_SET_H_
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
* The following macros are used to declare global sets of objects, which
|
|
44
|
+
* are collected by the linker into a `linker_set' as defined below.
|
|
45
|
+
* For ELF, this is done by constructing a separate segment for each set.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
* Private macros, not to be used outside this header file.
|
|
50
|
+
*/
|
|
51
|
+
#if defined(__APPLE__) && __MACH__
|
|
52
|
+
#define __MAKE_SET(set, sym) \
|
|
53
|
+
static void const * const __set_##set##_sym_##sym \
|
|
54
|
+
__section("__DATA,set_" #set) __used = &sym
|
|
55
|
+
#else
|
|
56
|
+
#define __MAKE_SET(set, sym) \
|
|
57
|
+
__GLOBL(__CONCAT(__start_set_,set)); \
|
|
58
|
+
__GLOBL(__CONCAT(__stop_set_,set)); \
|
|
59
|
+
static void const * const __set_##set##_sym_##sym \
|
|
60
|
+
__section("set_" #set) __used = &sym
|
|
61
|
+
#endif
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
* Public macros.
|
|
65
|
+
*/
|
|
66
|
+
#define DATA_SET(set, sym) __MAKE_SET(set, sym)
|
|
67
|
+
|
|
68
|
+
/*
|
|
69
|
+
* Initialize before referring to a given linker set.
|
|
70
|
+
*/
|
|
71
|
+
#if defined(__APPLE__) && __MACH__
|
|
72
|
+
#define SET_DECLARE(set, ptype) \
|
|
73
|
+
extern ptype *__CONCAT(__start_set_,set) __asm("section$start$__DATA$set_" #set); \
|
|
74
|
+
extern ptype *__CONCAT(__stop_set_,set) __asm("section$end$__DATA$set_" #set);
|
|
75
|
+
#define SET_DECLARE_WEAK SET_DECLARE
|
|
76
|
+
#else
|
|
77
|
+
#define SET_DECLARE(set, ptype) \
|
|
78
|
+
extern ptype *__CONCAT(__start_set_,set); \
|
|
79
|
+
extern ptype *__CONCAT(__stop_set_,set)
|
|
80
|
+
#define SET_DECLARE_WEAK(set, ptype) \
|
|
81
|
+
extern ptype __weak_sym *__CONCAT(__start_set_,set); \
|
|
82
|
+
extern ptype __weak_sym *__CONCAT(__stop_set_,set)
|
|
83
|
+
#endif
|
|
84
|
+
|
|
85
|
+
#define SET_BEGIN(set) \
|
|
86
|
+
(&__CONCAT(__start_set_,set))
|
|
87
|
+
#define SET_LIMIT(set) \
|
|
88
|
+
(&__CONCAT(__stop_set_,set))
|
|
89
|
+
|
|
90
|
+
/*
|
|
91
|
+
* Iterate over all the elements of a set.
|
|
92
|
+
*
|
|
93
|
+
* Sets always contain addresses of things, and "pvar" points to words
|
|
94
|
+
* containing those addresses. Thus is must be declared as "type **pvar",
|
|
95
|
+
* and the address of each set item is obtained inside the loop by "*pvar".
|
|
96
|
+
*/
|
|
97
|
+
#define SET_FOREACH(pvar, set) \
|
|
98
|
+
for (pvar = SET_BEGIN(set); pvar < SET_LIMIT(set); pvar++)
|
|
99
|
+
|
|
100
|
+
#define SET_ITEM(set, i) \
|
|
101
|
+
((SET_BEGIN(set))[i])
|
|
102
|
+
|
|
103
|
+
/*
|
|
104
|
+
* Provide a count of the items in a set.
|
|
105
|
+
*/
|
|
106
|
+
#define SET_COUNT(set) \
|
|
107
|
+
(SET_LIMIT(set) - SET_BEGIN(set))
|
|
108
|
+
|
|
109
|
+
#endif /* _SYS_LINKER_SET_H_ */
|