diff options
| author | = <jakob@memeware.net> | 2017-05-15 16:41:12 -0400 |
|---|---|---|
| committer | = <jakob@memeware.net> | 2017-05-15 16:41:12 -0400 |
| commit | ba4fad8c5a409dd0738bc09a95cbdebf360aa496 (patch) | |
| tree | 989dfc5e3594a74ce2e4fcd4014b8db7b33b4629 /src/main.c | |
| parent | 2ba0b505ce1ee748f42a85f7e27906737fa47fc8 (diff) | |
Began finalization of the table dumping functionality
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 45 |
1 files changed, 34 insertions, 11 deletions
@@ -208,16 +208,16 @@ static void create_archive(char **paths, int argc, struct params p) { return; } - struct table_entry *root = calloc(sizeof(struct table_entry), 1); + struct table_entry *root = calloc(sizeof(struct table_entry), 1); struct table_entry *cur; - struct header *h = create_header(); - struct stream *data = stream_new(1); - struct stream *table = stream_new(1); + struct header *h = create_header(); + struct stream *table_compressed, *data_compressed; + struct stream *data = stream_new(1); + struct stream *table = stream_new(1); struct stream *file; - uint64_t data_size = 0; - uint64_t table_size; + uint64_t data_size = 0; + uint64_t table_size = 0; - dump_header(fp, h); for (int i = 1; i < argc - p.vararg_index; i++) { file = stream_from_file(paths[i]); if (file == NULL) { @@ -228,11 +228,34 @@ static void create_archive(char **paths, int argc, struct params p) { data_size += file->len; stream_concat(data, file, file->len); cur = add_file(root, paths[i]); + /* TODO: Separate into own function. */ + table_size += 20 + strlen(cur->filename) * 2; + table_size += 28 * cur->segment_count + 48; } - stream_seek(data, 0, SEEK_SET); - stream_dump(fp, data, data_size); - table_size = dump_table(table, root); - stream_dump(fp, table, table_size); + + h->table_size = table_size; + h->table_offset = 40 + data_size; + + dump_table(table, root); + + data_compressed = stream_deflate(data, data_size); + table_compressed = stream_deflate(table, table_size); + stream_free(data); + stream_free(table); + + dump_header(fp, h); + /* FIXME: Formatting and this initial seek might not be necessary. */ + stream_seek(data_compressed, 0, SEEK_SET); + stream_dump(fp, data_compressed, data_size); + + /* FIXME: May be an incompatible value. Also, move this shitty hack. */ + uint8_t compressed = 0x80; + uint64_t len = table_compressed->len, decompressed_len = table_size; + fwrite(&compressed, sizeof(uint8_t), 1, fp); + fwrite(&len, sizeof(uint64_t), 1, fp); + fwrite(&decompressed_len, sizeof(uint64_t), 1, fp); + + stream_dump(fp, table_compressed, table_size); } |