aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/package/archiver
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-02 05:56:56 +0900
committernsfisis <nsfisis@gmail.com>2026-08-02 05:56:56 +0900
commit4fa973840f0a0e2cbb16f5e3341c0625793af2ed (patch)
tree6fcf9342ad97302fcb065e642309b6ccf81fe87c /crates/shirabe/src/package/archiver
parent73911c5da18cd37761f90a15558d76d5742f38e5 (diff)
downloadphp-shirabe-4fa973840f0a0e2cbb16f5e3341c0625793af2ed.tar.gz
php-shirabe-4fa973840f0a0e2cbb16f5e3341c0625793af2ed.tar.zst
php-shirabe-4fa973840f0a0e2cbb16f5e3341c0625793af2ed.zip
refactor(php-shim): drop pack/unpack in favor of direct byte handling
The only callers were trivial fixed-format uses: reading the first four hash bytes as a native int, splitting in_addr byte strings, and building a constant ZIP EOCD record. Each site now does the byte manipulation directly, so the general-purpose shims are no longer needed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/package/archiver')
-rw-r--r--crates/shirabe/src/package/archiver/phar_archiver.rs26
-rw-r--r--crates/shirabe/src/package/archiver/zip_archiver.rs24
2 files changed, 21 insertions, 29 deletions
diff --git a/crates/shirabe/src/package/archiver/phar_archiver.rs b/crates/shirabe/src/package/archiver/phar_archiver.rs
index 55e4cb95..fbab8c67 100644
--- a/crates/shirabe/src/package/archiver/phar_archiver.rs
+++ b/crates/shirabe/src/package/archiver/phar_archiver.rs
@@ -5,8 +5,8 @@ use crate::package::archiver::ArchivableFilesFinder;
use crate::package::archiver::ArchiverInterface;
use indexmap::IndexMap;
use shirabe_php_shim::{
- FilesystemIterator, Phar, PharData, PhpMixed, RuntimeException, bzcompress, file_exists,
- file_put_contents, function_exists, gzcompress, pack, str_repeat, strrpos, unlink,
+ FilesystemIterator, Phar, PharData, RuntimeException, bzcompress, file_exists,
+ file_put_contents, function_exists, gzcompress, str_repeat, strrpos, unlink,
};
fn formats() -> IndexMap<&'static str, i64> {
@@ -88,19 +88,15 @@ impl ArchiverInterface for PharArchiver {
file_put_contents(&target, &str_repeat("\0", 10240).into_bytes());
} else if format == "zip" {
// create minimal valid ZIP file (Empty Central Directory + End of Central Directory record)
- let eocd = pack(
- "VvvvvVVv",
- &[
- PhpMixed::Int(0x06054b50), // End of central directory signature
- PhpMixed::Int(0), // Number of this disk
- PhpMixed::Int(0), // Disk where central directory starts
- PhpMixed::Int(0), // Number of central directory records on this disk
- PhpMixed::Int(0), // Total number of central directory records
- PhpMixed::Int(0), // Size of central directory (bytes)
- PhpMixed::Int(0), // Offset of start of central directory
- PhpMixed::Int(0), // Comment length
- ],
- );
+ let mut eocd = Vec::with_capacity(22);
+ eocd.extend_from_slice(&0x06054b50u32.to_le_bytes()); // End of central directory signature
+ eocd.extend_from_slice(&0u16.to_le_bytes()); // Number of this disk
+ eocd.extend_from_slice(&0u16.to_le_bytes()); // Disk where central directory starts
+ eocd.extend_from_slice(&0u16.to_le_bytes()); // Number of central directory records on this disk
+ eocd.extend_from_slice(&0u16.to_le_bytes()); // Total number of central directory records
+ eocd.extend_from_slice(&0u32.to_le_bytes()); // Size of central directory (bytes)
+ eocd.extend_from_slice(&0u32.to_le_bytes()); // Offset of start of central directory
+ eocd.extend_from_slice(&0u16.to_le_bytes()); // Comment length
file_put_contents(&target, &eocd);
} else if format == "tar.gz" || format == "tar.bz2" {
let compress_algo = *compress_formats.get(format.as_str()).unwrap();
diff --git a/crates/shirabe/src/package/archiver/zip_archiver.rs b/crates/shirabe/src/package/archiver/zip_archiver.rs
index 41201b56..bf0144fb 100644
--- a/crates/shirabe/src/package/archiver/zip_archiver.rs
+++ b/crates/shirabe/src/package/archiver/zip_archiver.rs
@@ -6,7 +6,7 @@ use crate::util::Filesystem;
use crate::util::Platform;
use indexmap::IndexMap;
use shirabe_php_shim::{
- PhpMixed, RuntimeException, ZipArchive, class_exists, fileperms, method_exists, pack, realpath,
+ PhpMixed, RuntimeException, ZipArchive, class_exists, fileperms, method_exists, realpath,
};
use std::path::PathBuf;
@@ -93,19 +93,15 @@ impl ArchiverInterface for ZipArchiver {
if zip.close() {
if !std::path::Path::new(&target).exists() {
// create minimal valid ZIP file (Empty Central Directory + End of Central Directory record)
- let eocd = pack(
- "VvvvvVVv",
- &[
- PhpMixed::Int(0x06054b50), // End of central directory signature
- PhpMixed::Int(0), // Number of this disk
- PhpMixed::Int(0), // Disk where central directory starts
- PhpMixed::Int(0), // Number of central directory records on this disk
- PhpMixed::Int(0), // Total number of central directory records
- PhpMixed::Int(0), // Size of central directory (bytes)
- PhpMixed::Int(0), // Offset of start of central directory
- PhpMixed::Int(0), // Comment length
- ],
- );
+ let mut eocd = Vec::with_capacity(22);
+ eocd.extend_from_slice(&0x06054b50u32.to_le_bytes()); // End of central directory signature
+ eocd.extend_from_slice(&0u16.to_le_bytes()); // Number of this disk
+ eocd.extend_from_slice(&0u16.to_le_bytes()); // Disk where central directory starts
+ eocd.extend_from_slice(&0u16.to_le_bytes()); // Number of central directory records on this disk
+ eocd.extend_from_slice(&0u16.to_le_bytes()); // Total number of central directory records
+ eocd.extend_from_slice(&0u32.to_le_bytes()); // Size of central directory (bytes)
+ eocd.extend_from_slice(&0u32.to_le_bytes()); // Offset of start of central directory
+ eocd.extend_from_slice(&0u16.to_le_bytes()); // Comment length
std::fs::write(&target, &eocd)?;
}