feat: add public API header and format spec

This commit is contained in:
2026-09-14 23:20:32 +02:00
parent 4af011233d
commit 8287541447
4 changed files with 134 additions and 2 deletions
+63
View File
@@ -0,0 +1,63 @@
#ifndef FPK_H
#define FPK_H
#include <stddef.h>
#include <stdint.h>
#define FPK_MAGIC "FPK1"
#define FPK_MAGIC_SIZE 4
#define FPK_VERSION 1
#define FPK_HEADER_SIZE 28
/*
* magic 4
* entry_count 8
* dir_offset 8
* strtab_offset 8
* --
* 28
*/
#define FPK_DIR_ENTRY_SIZE 25
/*
* path_offset 8
* data_offset 8
* data_size 8
* method 1
* --
* 25
*/
#define FPK_METHOD_STORE 0
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
const char *path;
uint64_t data_offset;
uint64_t data_size;
uint8_t method;
} fpk_entry_t;
struct fpk;
struct fpk_writer;
struct fpk *fpk_open(const char *path);
void fpk_close(struct fpk *fpk);
fpk_entry_t *fpk_find(struct fpk *fpk, const char *path);
void *fpk_read(struct fpk *fpk, const fpk_entry_t *entry, size_t *out_size);
uint64_t fpk_entry_count(const struct fpk *fpk);
const fpk_entry_t *fpk_entry_at(const struct fpk *fpk, uint64_t index);
struct fpk_writer *fpk_writer_open(const char *path);
int fpk_writer_add(struct fpk_writer *w, const char *path, const void *data,
size_t size);
int fpk_writer_finalize(struct fpk_writer *w);
void fpk_writer_close(struct fpk_writer *w);
#ifdef __cplusplus
}
#endif
#endif /* FPK_H */
+16
View File
@@ -0,0 +1,16 @@
#ifndef FPK_VERSION_H
#define FPK_VERSION_H
#define FPK_VERSION_MAJOR 0
#define FPK_VERSION_MINOR 1
#define FPK_VERSION_PATCH 0
#define FPK_STRINGIFY_HELPER(x) #x
#define FPK_STRINGIFY(x) FPK_STRINGIFY_HELPER(x)
#define FPK_VERSION_STRING \
FPK_STRINGIFY(FPK_VERSION_MAJOR) \
"." FPK_STRINGIFY(FPK_VERSION_MINOR) "." FPK_STRINGIFY( \
FPK_VERSION_PATCH)
#endif /* FPK_VERSION_H */