Skip to content

Commit 107d335

Browse files
authored
Share that APE files are also zip archives and how to use them! (#1319)
1 parent bd6630d commit 107d335

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tool/cosmocc/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,33 @@ format used by the host system; however it's also possible to explicitly
8888
convert APE programs to any architectures / OS combination. For further
8989
details on usage, run the `assimilate -h` command.
9090

91+
92+
## Binary archive format
93+
94+
The APE format includes another portability superpower: the ability to
95+
distribute application support files WITHIN the compiled executable file.
96+
This is because APE files are also mostly regular zip files! You will
97+
need a copy of a compatible zip tool like the modified version of
98+
Info-ZIP available here: https://cosmo.zip/pub/cosmos/bin/zip. With this
99+
in hand the following command:
100+
101+
```sh
102+
zip [APE file] [support_file.txt]
103+
```
104+
105+
adds support_file.txt to your executable. You can see it listed within
106+
the archive with `unzip -l [APE file]`.
107+
108+
Cosmo libc includes compatible file handling functions for accessing the
109+
contents of an APE file at the special '/zip' path. So your code is now
110+
able to do the following:
111+
112+
```c
113+
if (access( "/zip/support_file.txt", F_OK) == 0) {
114+
fprintf(stderr, "/zip/support_file.txt FOUND and can be used as an asset\n");
115+
}
116+
```
117+
91118
## Gotchas
92119

93120
If you use zsh and have trouble running APE programs try `sh -c ./prog`

0 commit comments

Comments
 (0)