From c969e39efe99dd6cb6462d2a7a4a3c82c41c3f88 Mon Sep 17 00:00:00 2001 From: "Hatter Jiang@Pixelbook" Date: Sat, 31 Aug 2019 15:04:32 +0800 Subject: [PATCH] add read_to_string --- src/util_io.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/util_io.rs b/src/util_io.rs index d0f98da..4a1a35d 100644 --- a/src/util_io.rs +++ b/src/util_io.rs @@ -1,15 +1,25 @@ use std::{ - io::{self, ErrorKind}, + io::{self, + ErrorKind, + prelude::*, + }, time::{SystemTime, Duration}, }; +use super::XResult; use super::util_size::get_display_size; use super::util_msg::print_lastline; pub const DEFAULT_BUF_SIZE: usize = 8 * 1024; +pub fn read_to_string(read: &mut dyn Read) -> XResult { + let mut buffer = String::new(); + read.read_to_string(&mut buffer)?; + Ok(buffer) +} + pub fn copy_io(reader: &mut R, writer: &mut W, total: i64) -> io::Result where R: io::Read, W: io::Write { copy_io_with_head(reader, writer, total, "Downloading")