extension_api: Add support for downloading bzip2 files (#58112)

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
~- [ ] Tests cover the new/changed behavior~
- [x] Performance impact has been considered and is acceptable

Release Notes:

- feat(extension_api): add support to bzip2 downloads

---------

Co-authored-by: Finn Evers <finn@zed.dev>
This commit is contained in:
Gabriel
2026-11-06 08:04:15 +00:00
committed by GitHub
parent 4a6121bb0f
commit 0ad2e6b976
2 changed files with 24 additions and 1 deletions
@@ -21,6 +21,10 @@ world extension {
/// The type of a downloaded file.
enum downloaded-file-type {
/// A bzip2 file (`.bz2`).
bzip2,
/// A bzip2 tar archive (`.tar.bz2`).
bzip2-tar,
/// A gzipped file (`.gz`).
gzip,
/// A gzipped tar archive (`.tar.gz`).
@@ -7,7 +7,7 @@ use crate::wasm_host::{
use ::http_client::{AsyncBody, HttpRequestExt};
use ::settings::{Settings, WorktreeId};
use anyhow::{Context as _, Result, bail};
use async_compression::futures::bufread::GzipDecoder;
use async_compression::futures::bufread::{BzDecoder, GzipDecoder};
use async_tar::Archive;
use async_trait::async_trait;
use extension::{
@@ -1132,6 +1132,25 @@ impl ExtensionImports for WasmState {
.await
.with_context(|| format!("unzipping {path:?} archive"))?;
}
DownloadedFileType::Bzip2 => {
let body = BzDecoder::new(body);
futures::pin_mut!(body);
self.host
.fs
.create_file_with(&destination_path, body)
.await?;
}
DownloadedFileType::Bzip2Tar => {
let mut tar_bz2_bytes = Vec::new();
body.read_to_end(&mut tar_bz2_bytes).await?;
let decompressed_bytes =
BzDecoder::new(BufReader::new(tar_bz2_bytes.as_slice()));
futures::pin_mut!(decompressed_bytes);
self.host
.fs
.extract_tar_file(&destination_path, Archive::new(decompressed_bytes))
.await?;
}
}
Ok(())