1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/* Auto-generated by cbindgen - do not edit manually */
/**
* Compression mode for entries.
*/
typedef enum BindleCompress BindleCompress;
/**
* A binary archive for collecting files.
*
* Uses memory-mapped I/O for fast reads, supports optional zstd compression, and handles updates via shadowing.
* Files can be added incrementally without rewriting the entire archive.
*
* # Example
*
* ```no_run
* use bindle_file::{Bindle, Compress};
*
* let mut archive = Bindle::open("data.bndl")?;
* archive.add("file.txt", b"data", Compress::None)?;
* archive.save()?;
* # Ok::<(), std::io::Error>(())
* ```
*/
typedef struct Bindle Bindle;
/**
* A streaming reader for archive entries.
*
* Created by the archive's `reader()` method. Automatically decompresses compressed entries and tracks CRC32 for integrity verification.
*
* # Example
*
* ```no_run
* # use bindle_file::Bindle;
* # let archive = Bindle::open("data.bndl")?;
* let mut reader = archive.reader("file.txt")?;
* std::io::copy(&mut reader, &mut std::io::stdout())?;
* reader.verify_crc32()?;
* # Ok::<(), std::io::Error>(())
* ```
*/
typedef struct BindleReader BindleReader;
/**
* A streaming writer for adding entries to an archive.
*
* Created by [`Bindle::writer()`]. Automatically compresses data if requested and computes CRC32 for integrity verification.
*
* The writer must be closed with [`close()`](Writer::close) or will be automatically closed when dropped. After closing, call [`Bindle::save()`] to commit the index.
*
* # Example
*
* ```no_run
* use std::io::Write;
* use bindle_file::{Bindle, Compress};
*
* let mut archive = Bindle::open("data.bndl")?;
* let mut writer = archive.writer("file.txt", Compress::None)?;
* writer.write_all(b"data")?;
* writer.close()?;
* archive.save()?;
* # Ok::<(), std::io::Error>(())
* ```
*/
typedef struct BindleWriter BindleWriter;
/**
* Creates a new archive, overwriting any existing file.
*
* # Parameters
* * `path` - NUL-terminated path to the archive file
*
* # Returns
* A pointer to the Bindle handle, or NULL on error. Must be freed with `bindle_close()`.
*/
struct Bindle *;
/**
* Opens an existing archive or creates a new one.
*
* # Parameters
* * `path` - NUL-terminated path to the archive file
*
* # Returns
* A pointer to the Bindle handle, or NULL on error. Must be freed with `bindle_close()`.
*/
struct Bindle *;
/**
* Opens an existing archive. Returns NULL if the file doesn't exist.
*
* # Parameters
* * `path` - NUL-terminated path to the archive file
*
* # Returns
* A pointer to the Bindle handle, or NULL on error. Must be freed with `bindle_close()`.
*/
struct Bindle *;
/**
* Adds data to the archive with the given name.
*
* # Parameters
* * `ctx` - Bindle handle from `bindle_open()`
* * `name` - NUL-terminated entry name
* * `data` - Data bytes (may contain NUL bytes)
* * `data_len` - Length of data in bytes
* * `compress` - Compression mode (BindleCompressNone, BindleCompressZstd, or BindleCompressAuto)
*
* # Returns
* True on success. Call `bindle_save()` to commit changes.
*/
bool ;
/**
* Adds a file from the filesystem to the archive.
*
* # Parameters
* * `ctx` - Bindle handle from `bindle_open()`
* * `name` - NUL-terminated entry name
* * `path` - NUL-terminated path to file on disk
* * `compress` - Compression mode
*
* # Returns
* True on success. Call `bindle_save()` to commit changes.
*/
bool ;
/**
* Commits all pending changes to disk.
*
* Writes the index and footer. Must be called after add/remove operations.
*/
bool ;
/**
* Closes the archive and frees the handle.
*
* After calling this, the ctx pointer is no longer valid.
*/
void ;
/**
* Reads an entry from the archive, decompressing if needed.
*
* # Parameters
* * `ctx_ptr` - Bindle handle
* * `name` - NUL-terminated entry name
* * `out_len` - Output parameter for data length
*
* # Returns
* Pointer to data buffer, or NULL if not found or CRC32 check fails.
* Must be freed with `bindle_free_buffer()`.
*/
uint8_t *;
/**
* Frees a buffer returned by `bindle_read()`.
*/
void ;
/**
* Reads an uncompressed entry without allocating.
*
* Returns a pointer directly into the memory-mapped archive. Only works for uncompressed entries.
*
* # Parameters
* * `ctx` - Bindle handle
* * `name` - NUL-terminated entry name
* * `out_len` - Output parameter for data length
*
* # Returns
* Pointer into the mmap, or NULL if entry is compressed or doesn't exist.
* The pointer is valid as long as the Bindle handle is open. Do NOT free this pointer.
*/
const uint8_t *;
/**
* Returns the number of entries in the archive.
*/
size_t ;
/**
* Returns the name of the entry at the given index as a null-terminated C string.
*
* Use with `bindle_length()` to iterate over all entries. The pointer is valid as long as the Bindle handle is open.
* Do NOT free the returned pointer.
*/
const char *;
/**
* Reclaims space by removing shadowed data.
*
* Rebuilds the archive with only live entries.
*/
bool ;
/**
* Extracts all entries to a destination directory.
*/
bool ;
/**
* Recursively adds all files from a directory to the archive.
*
* Call `bindle_save()` to commit changes.
*/
bool ;
/**
* Returns true if an entry with the given name exists.
*/
bool ;
/**
* Removes an entry from the index.
*
* Returns true if the entry existed. Data remains in the file until `bindle_vacuum()` is called.
* Call `bindle_save()` to commit changes.
*/
bool ;
/**
* Creates a streaming writer for adding an entry.
*
* The writer must be closed with `bindle_writer_close()`, then call `bindle_save()` to commit.
* Do not access the Bindle handle while the writer is active.
*/
struct BindleWriter *;
/**
* Writes data to the writer.
*/
bool ;
/**
* Closes the writer and finalizes the entry.
*/
bool ;
/**
* Creates a streaming reader for an entry.
*
* Automatically decompresses if needed. Must be freed with `bindle_reader_close()`.
* Call `bindle_reader_verify_crc32()` after reading to verify integrity.
*/
struct BindleReader *;
/**
* Reads data from the reader into the provided buffer.
*
* Returns the number of bytes read, or -1 on error. Returns 0 on EOF.
*/
ptrdiff_t ;
/**
* Verify the CRC32 of data read from the reader.
* Should be called after reading all data to ensure integrity.
* Returns true if CRC32 matches, false otherwise.
*/
bool ;
/**
* Closes the reader and frees the handle.
*/
void ;
/**
* Gets the uncompressed size of an entry by name.
*
* # Parameters
* * `ctx` - Bindle handle
* * `name` - NUL-terminated entry name
*
* # Returns
* The uncompressed size in bytes, or 0 if the entry doesn't exist.
* Note: Returns 0 for both non-existent entries and zero-length entries.
*/
size_t ;
/**
* Gets the compression type of an entry by name.
*
* # Parameters
* * `ctx` - Bindle handle
* * `name` - NUL-terminated entry name
*
* # Returns
* The Compress value (0 = None, 1 = Zstd), or 0 if the entry doesn't exist.
*/
enum BindleCompress ;
/**
* Reads an entry into a pre-existing buffer.
*
* Decompresses if needed and verifies CRC32. Reads up to `buffer_len` bytes.
*
* # Parameters
* * `ctx` - Bindle handle
* * `name` - NUL-terminated entry name
* * `buffer` - Pre-allocated buffer to read into
* * `buffer_len` - Maximum number of bytes to read
*
* # Returns
* The number of bytes actually read, or 0 if the entry doesn't exist or CRC32 check fails.
* If the entry is larger than `buffer_len`, only `buffer_len` bytes are read.
*/
size_t ;
/* BINDLE_H */