mirror of
https://github.com/jht5945/finding.git
synced 2025-12-28 13:40:04 +08:00
update
This commit is contained in:
@@ -1,20 +1,15 @@
|
||||
|
||||
use std:: {
|
||||
fs::File,
|
||||
path::Path,
|
||||
io::prelude::*,
|
||||
};
|
||||
|
||||
use rust_util::{
|
||||
XResult,
|
||||
new_box_error,
|
||||
};
|
||||
use rust_util::{ XResult, new_box_error, };
|
||||
|
||||
pub fn read_file_content(file: &Path, large_file_len: u64) -> XResult<String> {
|
||||
if ! file.exists() {
|
||||
if !file.exists() {
|
||||
return Err(new_box_error(&format!("File not exists: {:?}", file)));
|
||||
}
|
||||
if ! file.is_file() {
|
||||
if !file.is_file() {
|
||||
return Err(new_box_error(&format!("File is not file: {:?}", file)));
|
||||
}
|
||||
let file_len = file.metadata()?.len();
|
||||
@@ -22,7 +17,7 @@ pub fn read_file_content(file: &Path, large_file_len: u64) -> XResult<String> {
|
||||
return Err(new_box_error(&format!("File too large: {:?}, len: {}", file, file_len)));
|
||||
}
|
||||
let mut f = File::open(file)?;
|
||||
let mut content = String::new();
|
||||
let mut content = String::with_capacity(file_len as usize);
|
||||
f.read_to_string(&mut content)?;
|
||||
|
||||
Ok(content)
|
||||
|
||||
Reference in New Issue
Block a user