From 0b48f4a46d24248e4c012ef37d25b5963c27a78c Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 23 Aug 2026 12:43:10 +0900 Subject: fix(fs): carry file_get_contents results as bytes file_get_contents() and file_get_contents_with_max_length() return Vec instead of a from_utf8_lossy'd String. Call sites whose consumer takes a &str still convert lossily and are marked TODO(bytes). file_get_contents_with_max_length() now reads at most the requested number of bytes instead of the whole file. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe-class-map-generator/src/php_file_parser.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'crates/shirabe-class-map-generator/src/php_file_parser.rs') diff --git a/crates/shirabe-class-map-generator/src/php_file_parser.rs b/crates/shirabe-class-map-generator/src/php_file_parser.rs index 0cb9180f..450bea90 100644 --- a/crates/shirabe-class-map-generator/src/php_file_parser.rs +++ b/crates/shirabe-class-map-generator/src/php_file_parser.rs @@ -28,8 +28,12 @@ impl PhpFileParser { "File at \"{}\" is not readable, check its permissions", path ); - } else if trim(file_get_contents(path).unwrap_or_default().as_str(), None) - .is_empty() + // TODO(bytes) + } else if trim( + &String::from_utf8_lossy(&file_get_contents(path).unwrap_or_default()), + None, + ) + .is_empty() { // The input file was really empty and thus contains no classes return Ok(vec![]); @@ -178,7 +182,7 @@ impl PhpFileParser { } if is_file(path) { - return file_get_contents(path).is_some(); + return file_get_contents(path).is_ok(); } // assume false otherwise -- cgit v1.3.1-4-g156e