mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-06 02:21:51 +00:00
#1180: read the set file through the checked reader
This commit is contained in:
1 parent
3c862cc20f
commit
fb3fd8ad3b
1 file changed
+2
-5
@@ -7,7 +7,6 @@
|
||||
//! shortcut contexts); a type command with no Default entry takes its Text entry.
|
||||
|
||||
use std::collections::{BTreeSet, HashMap};
|
||||
use std::io::Read;
|
||||
|
||||
use serde_json::{Value, json};
|
||||
|
||||
@@ -58,10 +57,8 @@ pub fn decode(bytes: &[u8]) -> Result<String, String> {
|
||||
|
||||
/// Reads and decodes a set file, refusing one over [`MAX_BYTES`].
|
||||
pub fn read_file(path: &str) -> Result<String, String> {
|
||||
let file = std::fs::File::open(path).map_err(|e| format!("can't open {path}: {e}"))?;
|
||||
let mut bytes = Vec::new();
|
||||
let cap = u64::try_from(MAX_BYTES).unwrap_or(u64::MAX).saturating_add(1);
|
||||
file.take(cap).read_to_end(&mut bytes).map_err(|e| format!("can't read {path}: {e}"))?;
|
||||
let cap = u64::try_from(MAX_BYTES).unwrap_or(u64::MAX);
|
||||
let bytes = designcraft_engine::io::read_capped(path, cap).map_err(|e| format!("can't read {path}: {e}"))?;
|
||||
decode(&bytes)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user