diff --git a/crates/niva/Cargo.toml b/crates/niva/Cargo.toml index fcc3bcf..188c270 100644 --- a/crates/niva/Cargo.toml +++ b/crates/niva/Cargo.toml @@ -44,6 +44,7 @@ png = "0.17.7" sys-locale = "0.2.4" url = "2.3.1" glob = "0.3.1" +encoding_rs = "0.8.32" [target.'cfg(target_os = "macos")'.dependencies] cocoa = { version = "0.24.1" } diff --git a/crates/niva/src/app/api/fs.rs b/crates/niva/src/app/api/fs.rs index 2db33f9..c6eecd1 100644 --- a/crates/niva/src/app/api/fs.rs +++ b/crates/niva/src/app/api/fs.rs @@ -50,6 +50,8 @@ enum EncodeType { UTF8, #[serde(rename = "base64")] BASE64, + #[serde(rename = "gbk")] + GBK } #[niva_api] @@ -60,6 +62,14 @@ fn read(path: String, encode: Option) -> Result { EncodeType::BASE64 => { let content = std::fs::read(path)?; base64::encode(content) + }, + EncodeType::GBK => { + use encoding_rs::GBK; + let content = std::fs::read(path)?; + let mut buf = Vec::new(); + file.read_to_end(&mut buf).unwrap(); + let (decode_str, _, _) = GBK.decode(&buf); + let content: String = decode_str.into(); } };