oven-sh/bun · error · Error
Invalid gzip data
Error message
Invalid gzip data
What it means
downloadBun() fetches the platform tarball from registry.npmjs.org and decompresses it with unzipSync; if decompression throws, the error is wrapped as 'Invalid gzip data' with the underlying cause attached. In practice the bytes were not a valid gzip/tgz stream: a truncated download, an HTML error page saved as the body, or a tarball altered in transit.
Source
Thrown at packages/bun-release/src/npm/install.ts:100
}
} finally {
try {
rm(cwd);
} catch (error) {
debug("rm failed", error);
// There is nothing to do if the directory cannot be cleaned up.
}
}
}
async function downloadBun(platform: Platform, dst: string): Promise<void> {
const response = await fetch(`https://registry.npmjs.org/${owner}/${platform.bin}/-/${platform.bin}-${version}.tgz`);
const tgz = await response.arrayBuffer();
let buffer: Buffer;
try {
buffer = unzipSync(tgz);
} catch (cause) {
throw new Error("Invalid gzip data", { cause });
}
function str(i: number, n: number): string {
return String.fromCharCode(...buffer.subarray(i, i + n)).replace(/\0.*$/, "");
}
let offset = 0;
while (offset < buffer.length) {
const name = str(offset, 100).replace("package/", "");
const size = parseInt(str(offset + 124, 12), 8);
offset += 512;
if (!isNaN(size)) {
const entryPath = join(dst, name);
const entryName = relative(dst, entryPath);
if (entryName && !entryName.startsWith("..") && !isAbsolute(entryName)) {
write(entryPath, buffer.subarray(offset, offset + size));
if (name === platform.exe) {
try {
chmod(entryPath, 0o755);
} catch (error) {View on GitHub (pinned to 8c5296ac45)
Solutions
- Retry the install after clearing cache (npm cache clean --force, remove node_modules)
- Verify the tarball manually: download the URL and run 'tar -tzf' on it — if it is HTML, fix the registry/proxy
- Check the HTTP status before trusting the body and bypass the offending proxy for registry.npmjs.org
- Use the standalone install script which downloads from bun.com instead
Example fix
// before
const tgz = await (await fetch(url)).arrayBuffer();
const buf = unzipSync(tgz);
// after
const res = await fetch(url);
if (!res.ok) throw new Error(`registry responded ${res.status}`);
const tgz = Buffer.from(await res.arrayBuffer());
if (tgz[0] !== 0x1f || tgz[1] !== 0x8b) throw new Error('not a gzip stream');
const buf = unzipSync(tgz); Defensive patterns
Strategy: retry
Validate before calling
const tgz = Buffer.from(await res.arrayBuffer());
const isGzip = tgz.length > 2 && tgz[0] === 0x1f && tgz[1] === 0x8b;
if (!res.ok || !isGzip) throw new Error('tarball is not gzip — registry/proxy problem'); Try / catch
try {
buffer = unzipSync(tgz);
} catch (cause) {
throw new Error('Invalid gzip data', { cause }); // keep the cause for diagnosis; retry the download
} Prevention
- Check res.ok and gzip magic bytes before decompressing downloaded archives
- Pin a trustworthy registry endpoint; bypass MITM proxies for registry.npmjs.org when archives get altered
- Clear caches when retrying so a corrupted cached artifact is not reused
When it happens
Trigger: A proxy or registry mirror returning 200 with an HTML error page; a truncated response on a flaky connection; disk-full producing a short file; MITM/antivirus rewriting the archive.
Common situations: Self-hosted npm registries serving cached/corrupted artifacts; CI networks with aggressive inspection; intermittent connections during postinstall downloads.
Related errors
- Failed to install package "${module}"
- page-cache eviction failed for ${path}; results would be war
- not called
- Unsupported platform: ${os} ${arch} ${abi || ""}
- Your package manager doesn't seem to support bun. To use bun
AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16).
Data as JSON: /api/errors/d0732cfb08b162e8.
Report an issue: GitHub.