mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-27 15:40:03 +08:00
add read_to_bytes
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rust_util"
|
name = "rust_util"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Hatter's Rust Util"
|
description = "Hatter's Rust Util"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
readme = "README.md"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libc = "0.2.65"
|
libc = "0.2.65"
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ pub fn read_to_string(read: &mut dyn Read) -> XResult<String> {
|
|||||||
Ok(buffer)
|
Ok(buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn read_to_bytes(read: &mut dyn Read) -> XResult<Vec<u8>> {
|
||||||
|
let mut buffer = vec![];
|
||||||
|
read.read_to_end(&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