-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy patharchives.c
More file actions
63 lines (50 loc) · 1.8 KB
/
Copy patharchives.c
File metadata and controls
63 lines (50 loc) · 1.8 KB
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
/*
Shows basic usage of how to make use of archives with the library.
This examples depends on the ZIP backend which is located in the "extras" folder.
Like the hello_world example, this will load a file and print it to the console. The difference is
that this example will support the ability to load files from a ZIP archive.
When loading from an archive, you need to specify the backend and map it to a file extension. The
extension is what the library uses to determine which backend to use when opening a file.
To see this in action, consider specifying a file path like "archive.zip/file.txt". This will
ensure the file is loaded from the ZIP archive.
*/
#include "../fs.h"
#include "../extras/backends/zip/fs_zip.h" /* <-- This is where FS_ZIP is declared. */
#include <stdio.h>
int main(int argc, char** argv)
{
fs_result result;
fs* pFS;
fs_config fsConfig;
fs_file* pFile;
char buffer[4096];
size_t bytesRead;
fs_archive_type pArchiveTypes[] =
{
{FS_ZIP, "zip"}
};
if (argc < 2) {
printf("Usage: archives <file>\n");
return 1;
}
fsConfig = fs_config_init_default();
fsConfig.pArchiveTypes = pArchiveTypes;
fsConfig.archiveTypeCount = sizeof(pArchiveTypes) / sizeof(pArchiveTypes[0]);
result = fs_init(&fsConfig, &pFS);
if (result != FS_SUCCESS) {
printf("Failed to initialize file system: %d\n", result);
return 1;
}
result = fs_file_open(pFS, argv[1], FS_READ, &pFile);
if (result != FS_SUCCESS) {
fs_uninit(pFS);
printf("Failed to open file: %d\n", result);
return 1;
}
while (fs_file_read(pFile, buffer, sizeof(buffer), &bytesRead) == FS_SUCCESS) {
printf("%.*s", (int)bytesRead, buffer);
}
fs_file_close(pFile);
fs_uninit(pFS);
return 0;
}