Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 131 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ reqwest = { version = "0.12", features = ["blocking"] }
zip = "2"
tar = "0.4"
zstd = "0.13"
flate2 = "1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
anyhow = "1"
ctcb-manifest = "0.4.1"
dirs = "5"
strsim = "0.11"
crossterm = "0.28"
tokio = { version = "1", features = ["rt-multi-thread", "macros", "net", "fs", "signal"] }
Expand Down
3 changes: 3 additions & 0 deletions crates/fastled-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ reqwest = { workspace = true }
zip = { workspace = true }
tar = { workspace = true }
zstd = { workspace = true }
flate2 = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
anyhow = { workspace = true }
Expand All @@ -29,6 +30,8 @@ tokio = { workspace = true }
axum = { workspace = true }
tower-http = { workspace = true }
tokio-stream = { workspace = true }
ctcb-manifest = { workspace = true }
dirs = { workspace = true }
tempfile = "3"

[package.metadata.binstall]
Expand Down
45 changes: 41 additions & 4 deletions crates/fastled-cli/src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
//! * `.zip` extraction (general-purpose)
//! * Writing the `.emscripten` config file after installation

// This module is library code — not yet wired into the CLI entry point.
// Suppress dead-code lints until a later integration phase.
#![allow(dead_code)]

use std::fs::{self, File};
use std::io::{BufReader, BufWriter, Read, Write};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -190,6 +186,47 @@ pub fn extract_zip(archive: &Path, dest: &Path) -> Result<()> {
Ok(())
}

// ---------------------------------------------------------------------------
// Single-file extraction from a gzipped tar (.tgz)
// ---------------------------------------------------------------------------

/// Extract a single member from a `.tgz` archive into `dest`.
///
/// Used to pluck the esbuild binary out of an npm-style tarball (`package/...`
/// layout) without unpacking the whole archive.
///
/// # Errors
/// Returns an error if the archive cannot be read or if `member` is not
/// present in the archive.
pub fn extract_member_from_tgz(archive: &Path, member: &str, dest: &Path) -> Result<()> {
let file = File::open(archive)
.with_context(|| format!("cannot open archive {}", archive.display()))?;
let gz = flate2::read::GzDecoder::new(BufReader::new(file));
let mut tar_archive = tar::Archive::new(gz);

for entry in tar_archive
.entries()
.with_context(|| format!("cannot iterate entries of {}", archive.display()))?
{
let mut entry = entry.with_context(|| format!("bad entry in {}", archive.display()))?;
let path = entry
.path()
.with_context(|| format!("bad entry path in {}", archive.display()))?;
if path.to_string_lossy() == member {
if let Some(parent) = dest.parent() {
fs::create_dir_all(parent)
.with_context(|| format!("cannot create parent {}", parent.display()))?;
}
let mut out =
File::create(dest).with_context(|| format!("cannot create {}", dest.display()))?;
std::io::copy(&mut entry, &mut out)
.with_context(|| format!("cannot write {}", dest.display()))?;
return Ok(());
}
}
anyhow::bail!("member {member} not found in {}", archive.display());
}

// ---------------------------------------------------------------------------
// .emscripten config generation
// ---------------------------------------------------------------------------
Expand Down
Loading
Loading