Rendley docs

Assets and project state

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 a Uint8Array directly. Set takeOwnership to true to 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 a Uint8Array without 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");