diff --git a/crates/extension_api/wit/since_v0.8.0/extension.wit b/crates/extension_api/wit/since_v0.8.0/extension.wit index 052d670364b..c4c5942c5dc 100644 --- a/crates/extension_api/wit/since_v0.8.0/extension.wit +++ b/crates/extension_api/wit/since_v0.8.0/extension.wit @@ -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`). diff --git a/crates/extension_host/src/wasm_host/wit/since_v0_8_0.rs b/crates/extension_host/src/wasm_host/wit/since_v0_8_0.rs index 0c17b309f12..1b3444b2cba 100644 --- a/crates/extension_host/src/wasm_host/wit/since_v0_8_0.rs +++ b/crates/extension_host/src/wasm_host/wit/since_v0_8_0.rs @@ -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(())