aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-shim
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-18 07:29:18 +0900
committernsfisis <nsfisis@gmail.com>2026-08-18 07:29:18 +0900
commite2a46e4281920867ba37c67fddbaaa2820f067d2 (patch)
treeb472872b46f8182aef1350493209f2d0176de185 /crates/shirabe-php-shim
parent6a7e64d04a8b0ad932169df43e2d93efe8ceedf8 (diff)
downloadphp-shirabe-e2a46e4281920867ba37c67fddbaaa2820f067d2.tar.gz
php-shirabe-e2a46e4281920867ba37c67fddbaaa2820f067d2.tar.zst
php-shirabe-e2a46e4281920867ba37c67fddbaaa2820f067d2.zip
refactor(zip): return a ZipEntryStat struct from stat_index
The stat array was modelled as IndexMap<String, PhpMixed>, forcing callers through untyped lookups with an unwrap_or(0) fallback PHP has no counterpart for. Only `size` and `comp_size` are kept: statIndex has a single call site in Composer and it reads nothing else. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-shim')
-rw-r--r--crates/shirabe-php-shim/src/zip.rs39
1 files changed, 13 insertions, 26 deletions
diff --git a/crates/shirabe-php-shim/src/zip.rs b/crates/shirabe-php-shim/src/zip.rs
index 4fab9aad..fe566ae4 100644
--- a/crates/shirabe-php-shim/src/zip.rs
+++ b/crates/shirabe-php-shim/src/zip.rs
@@ -1,7 +1,5 @@
use crate::ErrorException;
-use crate::PhpMixed;
use crate::{StreamBacking, StreamState};
-use indexmap::IndexMap;
use zip::write::SimpleFileOptions;
/// Test-only behaviour mirroring PHPUnit's `getMockBuilder('ZipArchive')->getMock()`, where
@@ -32,6 +30,14 @@ enum ZipState {
},
}
+/// One entry of an archive, as returned by [`ZipArchive::stat_index`]. Only fields that Composer
+/// accesses are ported.
+#[derive(Debug, Clone)]
+pub struct ZipEntryStat {
+ pub size: i64,
+ pub comp_size: i64,
+}
+
#[derive(Debug)]
pub struct ZipArchive {
pub num_files: i64,
@@ -113,35 +119,16 @@ impl ZipArchive {
self.num_files
}
- pub fn stat_index(&self, index: i64) -> Option<IndexMap<String, PhpMixed>> {
+ pub fn stat_index(&self, index: i64) -> Option<ZipEntryStat> {
let mut state = self.state.borrow_mut();
let ZipState::Reader(archive) = &mut *state else {
return None;
};
let file = archive.by_index(index as usize).ok()?;
- let mut stat = IndexMap::new();
- stat.insert(
- "name".to_string(),
- PhpMixed::String(file.name().to_string()),
- );
- stat.insert("index".to_string(), PhpMixed::Int(index));
- stat.insert("crc".to_string(), PhpMixed::Int(file.crc32() as i64));
- stat.insert("size".to_string(), PhpMixed::Int(file.size() as i64));
- // PHP exposes the last-modified time as a Unix timestamp. The `zip` crate
- // only surfaces a 2-second-precision MS-DOS datetime; no consumer reads
- // this field, so it is reported as 0 rather than reconstructing it.
- stat.insert("mtime".to_string(), PhpMixed::Int(0));
- stat.insert(
- "comp_size".to_string(),
- PhpMixed::Int(file.compressed_size() as i64),
- );
- let comp_method = match file.compression() {
- zip::CompressionMethod::Stored => 0,
- zip::CompressionMethod::Deflated => 8,
- _ => -1,
- };
- stat.insert("comp_method".to_string(), PhpMixed::Int(comp_method));
- Some(stat)
+ Some(ZipEntryStat {
+ size: file.size() as i64,
+ comp_size: file.compressed_size() as i64,
+ })
}
pub fn extract_to(&self, path: impl AsRef<std::path::Path>) -> Result<bool, ErrorException> {