| 1 |
#![allow(missing_docs)] |
| 2 |
|
| 3 |
use std::io; |
| 4 |
use std::io::{Read, Write}; |
| 5 |
|
| 6 |
/// Provides high level API for reading from a stream. |
| 7 |
pub mod stream { |
| 8 |
pub use crate::read::stream::*; |
| 9 |
} |
| 10 |
/// Types for creating ZIP archives. |
| 11 |
pub mod write { |
| 12 |
use crate::write::{FileOptionExtension, FileOptions}; |
| 13 |
/// Unstable methods for [`FileOptions`]. |
| 14 |
pub trait FileOptionsExt { |
| 15 |
/// Write the file with the given password using the deprecated ZipCrypto algorithm. |
| 16 |
/// |
| 17 |
/// This is not recommended for new archives, as ZipCrypto is not secure. |
| 18 |
fn with_deprecated_encryption(self, password: &[u8]) -> Self; |
| 19 |
} |
| 20 |
impl<'k, T: FileOptionExtension> FileOptionsExt for FileOptions<'k, T> { |
| 21 |
fn with_deprecated_encryption(self, password: &[u8]) -> FileOptions<'static, T> { |
| 22 |
self.with_deprecated_encryption(password) |
| 23 |
} |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
/// Helper methods for writing unsigned integers in little-endian form. |
| 28 |
pub trait LittleEndianWriteExt: Write { |
| 29 |
fn write_u16_le(&mut self, input: u16) -> io::Result<()> { |
| 30 |
self.write_all(&input.to_le_bytes()) |
| 31 |
} |
| 32 |
|
| 33 |
fn write_u32_le(&mut self, input: u32) -> io::Result<()> { |
| 34 |
self.write_all(&input.to_le_bytes()) |
| 35 |
} |
| 36 |
|
| 37 |
fn write_u64_le(&mut self, input: u64) -> io::Result<()> { |
| 38 |
self.write_all(&input.to_le_bytes()) |
| 39 |
} |
| 40 |
|
| 41 |
fn write_u128_le(&mut self, input: u128) -> io::Result<()> { |
| 42 |
self.write_all(&input.to_le_bytes()) |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
impl<W: Write + ?Sized> LittleEndianWriteExt for W {} |
| 47 |
|
| 48 |
/// Helper methods for reading unsigned integers in little-endian form. |
| 49 |
pub trait LittleEndianReadExt: Read { |
| 50 |
fn read_u16_le(&mut self) -> io::Result<u16> { |
| 51 |
let mut out = [0u8; 2]; |
| 52 |
self.read_exact(&mut out)?; |
| 53 |
Ok(u16::from_le_bytes(out)) |
| 54 |
} |
| 55 |
|
| 56 |
fn read_u32_le(&mut self) -> io::Result<u32> { |
| 57 |
let mut out = [0u8; 4]; |
| 58 |
self.read_exact(&mut out)?; |
| 59 |
Ok(u32::from_le_bytes(out)) |
| 60 |
} |
| 61 |
|
| 62 |
fn read_u64_le(&mut self) -> io::Result<u64> { |
| 63 |
let mut out = [0u8; 8]; |
| 64 |
self.read_exact(&mut out)?; |
| 65 |
Ok(u64::from_le_bytes(out)) |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
impl<R: Read> LittleEndianReadExt for R {} |