Zipping is CPU-bound, so doing it on the main thread would block the event
loop for the whole duration of a backup, which is why this used to shell
out to the system zip executable. A worker thread gives the same
non-blocking behaviour without depending on anything being installed on the
host. (Reading is a different matter - see zip-extract.ts.)
The archive is streamed, never assembled in memory: entries are compressed
and written out as they are added (see zip-writer.ts), so a backup of a
file store far larger than RAM works. Content generated in the main thread
(pack.json, table dumps, config) is handed over a buffer at a time, while
files already on disk are only named - the worker streams them itself.
Building a zip file on a worker thread.
Zipping is CPU-bound, so doing it on the main thread would block the event loop for the whole duration of a backup, which is why this used to shell out to the system
zipexecutable. A worker thread gives the same non-blocking behaviour without depending on anything being installed on the host. (Reading is a different matter - see zip-extract.ts.)The archive is streamed, never assembled in memory: entries are compressed and written out as they are added (see zip-writer.ts), so a backup of a file store far larger than RAM works. Content generated in the main thread (pack.json, table dumps, config) is handed over a buffer at a time, while files already on disk are only named - the worker streams them itself.