Skip to content

Commit cad8413

Browse files
committed
fix: fix encoding error
1 parent cab4deb commit cad8413

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

check-cmt/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license.workspace = true
77

88
[dependencies]
99
anyhow = "1.0.89"
10+
encoding_rs = "0.8.35"
1011
image = "0.25.2"
1112
isbn = "0.4.0"
1213
md5 = "0.7.0"

check-cmt/src/main.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tokio::{
1212
io::{AsyncReadExt, AsyncWriteExt, BufReader},
1313
};
1414
use webp::Encoder;
15-
use zip::ZipArchive;
15+
use zip::{HasZipMetadata, ZipArchive};
1616

1717
use metadata::*;
1818

@@ -330,7 +330,18 @@ fn build_tree(zip_path: &str) -> Result<Vec<FileNode>, anyhow::Error> {
330330
for i in 0..zip.len() {
331331
let entry = zip.by_index(i)?;
332332
let is_dir = entry.is_dir();
333-
let path = entry.name().trim_matches('/').to_string();
333+
334+
let raw_name = entry.name_raw();
335+
336+
let name = if entry.get_metadata().is_utf8 || String::from_utf8(raw_name.to_vec()).is_ok() {
337+
String::from_utf8_lossy(raw_name).into_owned()
338+
} else {
339+
let (cow, _, _) = encoding_rs::GB18030.decode(raw_name);
340+
cow.into_owned()
341+
};
342+
343+
let path = name.trim_matches('/').to_string();
344+
334345
let parts: Vec<&str> = path.split('/').filter(|s| !s.is_empty()).collect();
335346
if parts.is_empty() {
336347
continue;

0 commit comments

Comments
 (0)