mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-29 08:30:04 +08:00
add read_to_string
This commit is contained in:
@@ -1,15 +1,25 @@
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
io::{self, ErrorKind},
|
io::{self,
|
||||||
|
ErrorKind,
|
||||||
|
prelude::*,
|
||||||
|
},
|
||||||
time::{SystemTime, Duration},
|
time::{SystemTime, Duration},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::XResult;
|
||||||
use super::util_size::get_display_size;
|
use super::util_size::get_display_size;
|
||||||
use super::util_msg::print_lastline;
|
use super::util_msg::print_lastline;
|
||||||
|
|
||||||
pub const DEFAULT_BUF_SIZE: usize = 8 * 1024;
|
pub const DEFAULT_BUF_SIZE: usize = 8 * 1024;
|
||||||
|
|
||||||
|
|
||||||
|
pub fn read_to_string(read: &mut dyn Read) -> XResult<String> {
|
||||||
|
let mut buffer = String::new();
|
||||||
|
read.read_to_string(&mut buffer)?;
|
||||||
|
Ok(buffer)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn copy_io<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W, total: i64) -> io::Result<u64>
|
pub fn copy_io<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W, total: i64) -> io::Result<u64>
|
||||||
where R: io::Read, W: io::Write {
|
where R: io::Read, W: io::Write {
|
||||||
copy_io_with_head(reader, writer, total, "Downloading")
|
copy_io_with_head(reader, writer, total, "Downloading")
|
||||||
|
|||||||
Reference in New Issue
Block a user