Skip to content

Commit

Permalink
Merge pull request #443 from KisaragiEffective/use-fs-read-on-import
Browse files Browse the repository at this point in the history
  • Loading branch information
KisaragiEffective committed Sep 21, 2024
2 parents b963045 + b241d93 commit 10b3b00
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions packages/toy-blog/src/service/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ pub fn import(file_path: &Path, article_id: &ArticleId) -> Result<(), anyhow::Er
bail!("Non-file paths are not supported")
}

let content = {
let mut fd = BufReader::new(File::open(file_path)?);
let mut buf = vec![];
fd.read_to_end(&mut buf)?;
String::from_utf8(buf)
};
let content = std::fs::read_to_string(file_path);

match content {
Ok(content) => {
Expand All @@ -33,11 +28,7 @@ pub fn import(file_path: &Path, article_id: &ArticleId) -> Result<(), anyhow::Er
Ok(())
}
Err(err) => {
bail!("The file is not UTF-8: {err}\
Please review following list:\
- The file is not binary\
- The text is encoded with UTF-8\
Especially, importing Shift-JIS texts are NOT supported.")
bail!("The file could not be read: {err}")
}
}
}

0 comments on commit 10b3b00

Please sign in to comment.