Skip to content

🎥 Make videos programmatically with React

`@remotion/renderer`: Use yauzl directly for Chrome zip extraction

Jonny Burger6af20f238b01
diff --git a/bun.lock b/bun.lock
index 7472d5b0da..52c829ffe3 100644
--- a/bun.lock
+++ b/bun.lock
@@ -1313,10 +1313,10 @@
"@remotion/licensing": "workspace:*",
"@remotion/streaming": "workspace:*",
"execa": "5.1.1",
- "extract-zip": "2.0.1",
"remotion": "workspace:*",
"source-map": "0.8.0-beta.0",
"ws": "8.17.1",
+ "yauzl": "3.3.0",
},
"devDependencies": {
"@happy-dom/global-registrator": "14.5.1",
@@ -1326,6 +1326,7 @@
"@testing-library/react": "16.1.0",
"@types/node": "catalog:",
"@types/ws": "8.5.10",
+ "@types/yauzl": "2.10.3",
"@typescript/native-preview": "catalog:",
"eslint": "catalog:",
"react": "catalog:",
@@ -2544,6 +2545,9 @@
},
},
},
+ "patchedDependencies": {
+ },
"overrides": {
"@rspack/core": "1.7.6",
"caniuse-lite": "1.0.30001766",
@@ -5237,7 +5241,7 @@
"buffer": ["[email protected]", "", { "dependencies": { "base64-js": "1.5.1", "ieee754": "1.2.1" } }, "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA=="],
- "buffer-crc32": ["[email protected]", "", {}, "sha512-Db1SbgBS/fg/392AblrMJk97KggmvYhr4pB5ZIMTWtaivCPMWLkmb7m21cJvpvgK+J3nsU2CmmixNBZx4vFj/w=="],
+ "buffer-crc32": ["[email protected]", "", {}, "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ=="],
"buffer-equal-constant-time": ["[email protected]", "", {}, "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA=="],
@@ -8169,7 +8173,7 @@
"yargs-parser": ["[email protected]", "", {}, "sha512-rwu/ClNdSMpkSrUb+d6BRsSkLUq1fmfsY6TOpYzTwvwkg1/NRG85KBy3kq++A8LKQwX6lsu+aWad+2khvuXrqw=="],
- "yauzl": ["[email protected]", "", { "dependencies": { "buffer-crc32": "0.2.13", "fd-slicer": "1.1.0" } }, "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g=="],
+ "yauzl": ["[email protected]", "", { "dependencies": { "buffer-crc32": "~0.2.3", "pend": "~1.2.0" } }, "sha512-PtGEvEP30p7sbIBJKUBjUnqgTVOyMURc4dLo9iNyAJnNIEz9pm88cCXF21w94Kg3k6RXkeZh5DHOGS0qEONvNQ=="],
"yocto-queue": ["[email protected]", "", {}, "sha512-AyeEbWOu/TAXdxlV9wmGcR0+yh2j3vYPGOECcIj2S7MkrLyC7ne+oye2BKTItt0ii2PHk4cDy+95+LshzbXnGg=="],
@@ -9971,6 +9975,8 @@
"anymatch/picomatch": ["[email protected]", "", {}, "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA=="],
+ "archiver/buffer-crc32": ["[email protected]", "", {}, "sha512-Db1SbgBS/fg/392AblrMJk97KggmvYhr4pB5ZIMTWtaivCPMWLkmb7m21cJvpvgK+J3nsU2CmmixNBZx4vFj/w=="],
+
"archiver/readable-stream": ["[email protected]", "", { "dependencies": { "abort-controller": "3.0.0", "buffer": "6.0.3", "events": "3.3.0", "process": "0.11.10", "string_decoder": "1.3.0" } }, "sha512-oIGGmcpTLwPga8Bn6/Z75SVaH1z5dUut2ibSyAMVhmUggWpmDn2dapB0n7f8nwaSiRtepAsfJyfXIO5DCVAODg=="],
"archiver-utils/readable-stream": ["[email protected]", "", { "dependencies": { "abort-controller": "3.0.0", "buffer": "6.0.3", "events": "3.3.0", "process": "0.11.10", "string_decoder": "1.3.0" } }, "sha512-oIGGmcpTLwPga8Bn6/Z75SVaH1z5dUut2ibSyAMVhmUggWpmDn2dapB0n7f8nwaSiRtepAsfJyfXIO5DCVAODg=="],
@@ -10241,6 +10247,8 @@
"extract-zip/get-stream": ["[email protected]", "", { "dependencies": { "pump": "3.0.0" } }, "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA=="],
+ "extract-zip/yauzl": ["[email protected]", "", { "dependencies": { "buffer-crc32": "0.2.13", "fd-slicer": "1.1.0" } }, "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g=="],
+
"fast-glob/glob-parent": ["[email protected]", "", { "dependencies": { "is-glob": "4.0.3" } }, "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow=="],
"fdir/picomatch": ["[email protected]", "", {}, "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg=="],
@@ -11405,6 +11413,8 @@
"werift-common/debug": ["[email protected]", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA=="],
+ "werift-ice/buffer-crc32": ["[email protected]", "", {}, "sha512-Db1SbgBS/fg/392AblrMJk97KggmvYhr4pB5ZIMTWtaivCPMWLkmb7m21cJvpvgK+J3nsU2CmmixNBZx4vFj/w=="],
+
"werift-ice/debug": ["[email protected]", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA=="],
"whatwg-url/webidl-conversions": ["[email protected]", "", {}, "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg=="],
@@ -11425,8 +11435,6 @@
"yargs/string-width": ["[email protected]", "", { "dependencies": { "emoji-regex": "10.4.0", "get-east-asian-width": "1.2.0", "strip-ansi": "7.1.0" } }, "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ=="],
- "yauzl/buffer-crc32": ["[email protected]", "", {}, "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ=="],
-
"zip-stream/readable-stream": ["[email protected]", "", { "dependencies": { "abort-controller": "3.0.0", "buffer": "6.0.3", "events": "3.3.0", "process": "0.11.10", "string_decoder": "1.3.0" } }, "sha512-oIGGmcpTLwPga8Bn6/Z75SVaH1z5dUut2ibSyAMVhmUggWpmDn2dapB0n7f8nwaSiRtepAsfJyfXIO5DCVAODg=="],
"zustand/react": ["[email protected]", "", {}, "sha512-V8AVnmPIICiWpGfm6GLzCR/W5FXLchHop40W4nXBmdlEceh16rCN8O8LNWm5bh5XUX91fh7KpA+W0TgMKmgTpQ=="],
diff --git a/package.json b/package.json
index 354f74c118..4637c4d586 100644
--- a/package.json
+++ b/package.json
@@ -129,5 +129,8 @@
"vitest": "4.0.9",
"@typescript/native-preview": "7.0.0-dev.20260217.1"
}
+ },
+ "patchedDependencies": {
}
}
diff --git a/packages/renderer/package.json b/packages/renderer/package.json
index cab9c273a0..fd7ae1d7f6 100644
--- a/packages/renderer/package.json
+++ b/packages/renderer/package.json
@@ -22,7 +22,7 @@
},
"dependencies": {
"execa": "5.1.1",
- "extract-zip": "2.0.1",
+ "yauzl": "3.3.0",
"remotion": "workspace:*",
"@remotion/streaming": "workspace:*",
"source-map": "0.8.0-beta.0",
@@ -44,7 +44,8 @@
"@remotion/example-videos": "workspace:*",
"@remotion/eslint-config-internal": "workspace:*",
"eslint": "catalog:",
- "@types/node": "catalog:"
+ "@types/node": "catalog:",
+ "@types/yauzl": "2.10.3"
},
"optionalDependencies": {
"@remotion/compositor-darwin-arm64": "workspace:*",
diff --git a/packages/renderer/src/browser/BrowserFetcher.ts b/packages/renderer/src/browser/BrowserFetcher.ts
index cc68455f4c..da4d606531 100644
--- a/packages/renderer/src/browser/BrowserFetcher.ts
+++ b/packages/renderer/src/browser/BrowserFetcher.ts
@@ -18,12 +18,12 @@ import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import {promisify} from 'node:util';
-import extractZip from 'extract-zip';
import {downloadFile} from '../assets/download-file';
import {makeFileExecutableIfItIsNot} from '../compositor/make-file-executable';
import type {LogLevel} from '../log-level';
import {ChromeMode} from '../options/chrome-mode';
import type {DownloadBrowserProgressFn} from '../options/on-browser-download';
+import {extractZipArchive} from './extract-zip-archive';
import {
getChromeDownloadUrl,
isAmazonLinux2023,
@@ -180,7 +180,7 @@ export const downloadBrowser = async ({
logLevel,
abortSignal: new AbortController().signal,
});
- await extractZip(archivePath, {dir: outputPath});
+ await extractZipArchive(archivePath, outputPath);
const possibleSubdirs = [
'chrome-linux',
diff --git a/packages/renderer/src/browser/extract-zip-archive.ts b/packages/renderer/src/browser/extract-zip-archive.ts
new file mode 100644
index 0000000000..028172695f
--- /dev/null
+++ b/packages/renderer/src/browser/extract-zip-archive.ts
@@ -0,0 +1,157 @@
+import {createWriteStream} from 'node:fs';
+import {mkdir, realpath, symlink} from 'node:fs/promises';
+import * as path from 'node:path';
+import {buffer} from 'node:stream/consumers';
+import {pipeline} from 'node:stream/promises';
+import {promisify} from 'node:util';
+import yauzl, {type Entry, type ZipFile} from 'yauzl';
+
+const openZip = promisify(yauzl.open) as (
+ zipPath: string,
+ options: {lazyEntries: true},
+) => Promise<ZipFile>;
+
+const openReadStream = (
+ zipfile: ZipFile,
+ entry: Entry,
+): Promise<NodeJS.ReadableStream> => {
+ return new Promise((resolve, reject) => {
+ zipfile.openReadStream(entry, (err, readStream) => {
+ if (err) {
+ reject(err);
+ return;
+ }
+
+ if (!readStream) {
+ reject(new Error('Failed to open zip read stream'));
+ return;
+ }
+
+ resolve(readStream);
+ });
+ });
+};
+
+const getExtractedMode = (entryMode: number, isDir: boolean): number => {
+ if (entryMode !== 0) {
+ return entryMode;
+ }
+
+ return isDir ? 0o755 : 0o644;
+};
+
+const extractEntry = async ({
+ entry,
+ zipfile,
+ dir,
+}: {
+ entry: Entry;
+ zipfile: ZipFile;
+ dir: string;
+}): Promise<void> => {
+ if (entry.fileName.startsWith('__MACOSX/')) {
+ return;
+ }
+
+ const dest = path.join(dir, entry.fileName);
+ const destDir = path.dirname(dest);
+
+ await mkdir(destDir, {recursive: true});
+
+ const canonicalDestDir = await realpath(destDir);
+ const relativeDestDir = path.relative(dir, canonicalDestDir);
+
+ if (relativeDestDir.split(path.sep).includes('..')) {
+ throw new Error(
+ `Out of bound path "${canonicalDestDir}" found while processing file ${entry.fileName}`,
+ );
+ }
+
+ const mode = (entry.externalFileAttributes >> 16) & 0xffff;
+ const IFMT = 61440;
+ const IFDIR = 16384;
+ const IFLNK = 40960;
+ const symlinkEntry = (mode & IFMT) === IFLNK;
+ let isDir = (mode & IFMT) === IFDIR;
+
+ if (!isDir && entry.fileName.endsWith('/')) {
+ isDir = true;
+ }
+
+ const madeBy = entry.versionMadeBy >> 8;
+ if (!isDir && madeBy === 0 && entry.externalFileAttributes === 16) {
+ isDir = true;
+ }
+
+ const procMode = getExtractedMode(mode, isDir) & 0o777;
+ const destDirectory = isDir ? dest : path.dirname(dest);
+
+ await mkdir(destDirectory, {
+ recursive: true,
+ mode: isDir ? procMode : undefined,
+ });
+
+ if (isDir) {
+ return;
+ }
+
+ const readStream = await openReadStream(zipfile, entry);
+
+ if (symlinkEntry) {
+ const link = (await buffer(readStream)).toString();
+ await symlink(link, dest);
+ return;
+ }
+
+ await pipeline(readStream, createWriteStream(dest, {mode: procMode}));
+};
+
+export const extractZipArchive = async (
+ archivePath: string,
+ dir: string,
+): Promise<void> => {
+ if (!path.isAbsolute(dir)) {
+ throw new Error('Target directory is expected to be absolute');
+ }
+
+ await mkdir(dir, {recursive: true});
+ const resolvedDir = await realpath(dir);
+
+ const zipfile = await openZip(archivePath, {lazyEntries: true});
+
+ return new Promise<void>((resolve, reject) => {
+ let canceled = false;
+
+ const cancel = (err: unknown) => {
+ if (canceled) {
+ return;
+ }
+
+ canceled = true;
+ zipfile.close();
+ reject(err);
+ };
+
+ zipfile.on('error', cancel);
+
+ zipfile.on('close', () => {
+ if (!canceled) {
+ resolve();
+ }
+ });
+
+ zipfile.on('entry', (entry) => {
+ if (canceled) {
+ return;
+ }
+
+ extractEntry({entry, zipfile, dir: resolvedDir})
+ .then(() => {
+ zipfile.readEntry();
+ })
+ .catch(cancel);
+ });
+
+ zipfile.readEntry();
+ });
+};
diff --git a/patches/[email protected] b/patches/[email protected]
new file mode 100644
index 0000000000..5ca214265a
--- /dev/null
+++ b/patches/[email protected]
@@ -0,0 +1,161 @@
+diff --git a/fd-slicer.js b/fd-slicer.js
+index 956a979f2db5dcead8c69076f982ed935dd0b3f7..172bf2b6c2310a9e6ff672ffd4fdc19dfd7fe9e1 100644
+--- a/fd-slicer.js
++++ b/fd-slicer.js
+@@ -88,31 +88,32 @@ function ReadStream(context, options) {
+ this.start = options.start || 0;
+ this.endOffset = options.end;
+ this.pos = this.start;
+- this.destroyed = false;
++ this._destroyed = false;
+ }
+
+ ReadStream.prototype._read = function(n) {
+ var self = this;
+- if (self.destroyed) return;
++ if (self._destroyed) return;
+
+ var toRead = Math.min(self._readableState.highWaterMark, n);
+ if (self.endOffset != null) {
+ toRead = Math.min(toRead, self.endOffset - self.pos);
+ }
+ if (toRead <= 0) {
+- self.destroyed = true;
++ self._destroyed = true;
+ self.push(null);
+ self.context.unref();
+ return;
+ }
+ self.context.pend.go(function(cb) {
+- if (self.destroyed) return cb();
++ if (self._destroyed) return cb();
+ var buffer = Buffer.allocUnsafe(toRead);
+ fs.read(self.context.fd, buffer, 0, toRead, self.pos, function(err, bytesRead) {
++ if (self._destroyed) return cb();
+ if (err) {
+ self.destroy(err);
+ } else if (bytesRead === 0) {
+- self.destroyed = true;
++ self._destroyed = true;
+ self.push(null);
+ self.context.unref();
+ } else {
+@@ -125,11 +126,18 @@ ReadStream.prototype._read = function(n) {
+ };
+
+ ReadStream.prototype.destroy = function(err) {
+- if (this.destroyed) return;
+- err = err || new Error("stream destroyed");
+- this.destroyed = true;
+- this.emit('error', err);
+- this.context.unref();
++ if (err == null && !this.readableEnded) {
++ err = new Error("stream _destroyed");
++ }
++ return Readable.prototype.destroy.call(this, err);
++};
++
++ReadStream.prototype._destroy = function(err, cb) {
++ if (!this._destroyed) {
++ this._destroyed = true;
++ this.context.unref();
++ }
++ cb(err);
+ };
+
+ util.inherits(WriteStream, Writable);
+@@ -144,14 +152,14 @@ function WriteStream(context, options) {
+ this.endOffset = (options.end == null) ? Infinity : +options.end;
+ this.bytesWritten = 0;
+ this.pos = this.start;
+- this.destroyed = false;
++ this._destroyed = false;
+
+ this.on('finish', this.destroy.bind(this));
+ }
+
+ WriteStream.prototype._write = function(buffer, encoding, callback) {
+ var self = this;
+- if (self.destroyed) return;
++ if (self._destroyed) return;
+
+ if (self.pos + buffer.length > self.endOffset) {
+ var err = new Error("maximum file length exceeded");
+@@ -161,7 +169,7 @@ WriteStream.prototype._write = function(buffer, encoding, callback) {
+ return;
+ }
+ self.context.pend.go(function(cb) {
+- if (self.destroyed) return cb();
++ if (self._destroyed) return cb();
+ fs.write(self.context.fd, buffer, 0, buffer.length, self.pos, function(err, bytes) {
+ if (err) {
+ self.destroy();
+@@ -178,10 +186,12 @@ WriteStream.prototype._write = function(buffer, encoding, callback) {
+ });
+ };
+
+-WriteStream.prototype.destroy = function() {
+- if (this.destroyed) return;
+- this.destroyed = true;
+- this.context.unref();
++WriteStream.prototype._destroy = function(err, cb) {
++ if (!this._destroyed) {
++ this._destroyed = true;
++ this.context.unref();
++ }
++ cb(err);
+ };
+
+ util.inherits(BufferSlicer, EventEmitter);
+@@ -231,7 +241,7 @@ BufferSlicer.prototype.write = function(buffer, offset, length, position, callba
+ BufferSlicer.prototype.createReadStream = function(options) {
+ options = options || {};
+ var readStream = new PassThrough(options);
+- readStream.destroyed = false;
++ readStream._destroyed = false;
+ readStream.start = options.start || 0;
+ readStream.endOffset = options.end;
+ // by the time this function returns, we'll be done.
+@@ -254,8 +264,9 @@ BufferSlicer.prototype.createReadStream = function(options) {
+ }
+
+ readStream.end();
+- readStream.destroy = function() {
+- readStream.destroyed = true;
++ readStream._destroy = function(err, cb) {
++ readStream._destroyed = true;
++ PassThrough.prototype._destroy.call(readStream, err, cb);
+ };
+ return readStream;
+ };
+@@ -268,15 +279,15 @@ BufferSlicer.prototype.createWriteStream = function(options) {
+ writeStream.endOffset = (options.end == null) ? this.buffer.length : +options.end;
+ writeStream.bytesWritten = 0;
+ writeStream.pos = writeStream.start;
+- writeStream.destroyed = false;
++ writeStream._destroyed = false;
+ writeStream._write = function(buffer, encoding, callback) {
+- if (writeStream.destroyed) return;
++ if (writeStream._destroyed) return;
+
+ var end = writeStream.pos + buffer.length;
+ if (end > writeStream.endOffset) {
+ var err = new Error("maximum file length exceeded");
+ err.code = 'ETOOBIG';
+- writeStream.destroyed = true;
++ writeStream._destroyed = true;
+ callback(err);
+ return;
+ }
+@@ -287,8 +298,9 @@ BufferSlicer.prototype.createWriteStream = function(options) {
+ writeStream.emit('progress');
+ callback();
+ };
+- writeStream.destroy = function() {
+- writeStream.destroyed = true;
++ writeStream._destroy = function(err, cb) {
++ writeStream._destroyed = true;
++ cb(err);
+ };
+ return writeStream;
+ };