Zip Archive
The ZipArchive utility builds and reads .zip files inside the SDK’s FFmpeg virtual filesystem. Useful when you need to package multiple assets into a single download (for example: exporting a project with its thumbnails, or bundling a set of Lottie compositions with their images).
Create an Archive
import { ZipArchive } from "@rendley/sdk";
const archive = new ZipArchive();
await archive.create("/tmp/my-project.zip");
create(path) initializes an empty archive at the given path in the FFmpeg filesystem.
Open an Existing Archive
const archive = new ZipArchive();
await archive.open("/tmp/existing.zip");
Add Files
Two ways to add content:
addFile(path, targetDirectory?): add a file that already exists in the FFmpeg filesystem.addData(path, data, takeOwnership?): add aUint8Arraydirectly. SettakeOwnershiptotrueto skip copying the buffer (the archive will reuse it).addFiles(paths[], targetDirectory?): add multiple files in one call.
const ffmpeg = Engine.getInstance().getFFmpeg();
await ffmpeg.writeFile("/tmp/thumbnail.png", pngBytes);
await archive.addFile("/tmp/thumbnail.png");
await archive.addData(
"/project.json",
new TextEncoder().encode(JSON.stringify(state)),
);
Extract
extractAll(path): extract every entry into the given directory.extractFile(fromPath, toPath): extract a single entry.readFile(path): read an entry’s contents as aUint8Arraywithout writing it to disk.
await archive.extractAll("/tmp/output");
const json = await archive.readFile("/project.json");
List Contents
const paths = await archive.listFiles();
Save and Close
Call save() to flush pending writes. Use destroy() to release resources when you’re done.
await archive.save();
await archive.destroy();
Downloading the Result
After save(), download the file:
const ffmpeg = Engine.getInstance().getFFmpeg();
await ffmpeg.downloadFile("/tmp/my-project.zip");
See Also
- FFmpeg: the virtual filesystem the archive operates on.
- API reference:
ZipArchive