libsf3
Loading...
Searching...
No Matches
sf3_archive.h
Go to the documentation of this file.
1#ifndef __SF3_ARCHIVE__
2#define __SF3_ARCHIVE__
3#include "sf3_core.h"
4
6#define SF3_FORMAT_ID_ARCHIVE 0x01
7
20
24 uint64_t length;
27 char data[];
28};
29
34 struct sf3_identifier identifier;
38 uint64_t count;
40 uint64_t metadata_size;
42 uint64_t entry_offset[];
43};
44
49SF3_INLINE const struct sf3_archive_meta *sf3_archive_meta_entry(const struct sf3_archive *archive, uint64_t index){
50 if(archive->count <= index) return 0;
51 const char *base = (char *)&archive->entry_offset[archive->count];
52 base += archive->entry_offset[index];
53 return (const struct sf3_archive_meta *)base;
54}
55
58 return meta->mime_type.str;
59}
60
62SF3_INLINE const char *sf3_archive_meta_path(const struct sf3_archive_meta *meta){
63 return ((sf3_str16 *)(meta->mime_type.str + meta->mime_type.length))->str;
64}
65
70SF3_INLINE const struct sf3_file *sf3_archive_file(const struct sf3_archive *archive, uint64_t index){
71 if(archive->count <= index) return 0;
72 const char *base = (char *)&archive->entry_offset[0];
73 base += archive->metadata_size;
74 const uint64_t *offsets = (const uint64_t *)base;
75 base = (char*)(offsets+archive->count);
76 return (const struct sf3_file *)(base + offsets[index]);
77}
78
80SF3_EXPORT size_t sf3_archive_size(const struct sf3_archive *archive){
81 if(archive->count == 0) return sizeof(struct sf3_archive);
82 const struct sf3_file *file = sf3_archive_file(archive, archive->count-1);
83 const void *start = (const void *)archive;
84 const void *end = (const void *)file;
85 return (end-start)+sizeof(uint64_t)+file->length;
86}
87#endif
SF3_INLINE const char * sf3_archive_meta_mime_type(const struct sf3_archive_meta *meta)
Returns the C string for the mime-type.
Definition sf3_archive.h:57
SF3_INLINE const struct sf3_archive_meta * sf3_archive_meta_entry(const struct sf3_archive *archive, uint64_t index)
Definition sf3_archive.h:49
SF3_EXPORT size_t sf3_archive_size(const struct sf3_archive *archive)
Computes the size of the archive file in bytes.
Definition sf3_archive.h:80
SF3_INLINE const char * sf3_archive_meta_path(const struct sf3_archive_meta *meta)
Returns the C string for the relative file path.
Definition sf3_archive.h:62
SF3_INLINE const struct sf3_file * sf3_archive_file(const struct sf3_archive *archive, uint64_t index)
Definition sf3_archive.h:70
#define SF3_INLINE
Definition sf3_core.h:16
#define SF3_EXPORT
Definition sf3_core.h:13
#define SF3_PACK
Definition sf3_core.h:9
uint32_t sf3_crc32_checksum
Type for a CRC32 checksum.
Definition sf3_core.h:20
sf3_str8 mime_type
The media mime-type of the file contents.
Definition sf3_archive.h:18
sf3_crc32_checksum checksum
The CRC32 checksum of the file payload.
Definition sf3_archive.h:16
int64_t modtime
The last time the associated file was modified, as a UNIX timestamp.
Definition sf3_archive.h:14
uint64_t metadata_size
The size of the metadata block in bytes.
Definition sf3_archive.h:40
uint64_t entry_offset[]
The array of offsets for each metadata entry.
Definition sf3_archive.h:42
uint64_t count
Definition sf3_archive.h:38
A single file from an archive.
Definition sf3_archive.h:22
uint64_t length
The length of the data payload in bytes.
Definition sf3_archive.h:24
The basic header structure of every SF3 file.
Definition sf3_core.h:70
char str[]
Definition sf3_core.h:31
uint8_t length
Definition sf3_core.h:30