1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#![deny(missing_docs)]
#![allow(missing_copy_implementations)]
extern crate byteorder;
extern crate rand;
#[macro_use]
extern crate log;
#[cfg(test)]
#[cfg(feature="unstable")]
extern crate test;
use std::io::{self, Read};
#[cfg(feature="checksum")]
pub use self::checksum::adler::State32 as Adler32;
#[cfg(feature="checksum")]
pub mod checksum {
pub mod adler;
}
#[cfg(feature="bwt")]
pub mod bwt;
#[cfg(feature="flate")]
pub mod flate;
#[cfg(feature="lz4")]
pub mod lz4;
#[cfg(feature="zlib")]
pub mod zlib;
#[cfg(feature="entropy")]
pub mod entropy {
pub mod ari;
}
#[cfg(feature="rle")]
pub mod rle;
#[cfg(any(feature = "lz4", feature = "entropy", feature = "bwt"))]
fn byteorder_err_to_io(err: byteorder::Error) -> io::Error {
match err {
byteorder::Error::Io(e) => e,
byteorder::Error::UnexpectedEOF =>
io::Error::new(
io::ErrorKind::Other,
"unexpected end of file"
)
}
}
pub trait ReadExact: Read + Sized {
fn push_exactly(&mut self, bytes: u64, buf: &mut Vec<u8>) -> io::Result<()> {
let n = try!(self.by_ref().take(bytes).read_to_end(buf)) as u64;
if n < bytes {
return Err(io::Error::new(
io::ErrorKind::Other,
"unexpected end of file"
));
}
Ok(())
}
}
impl<T> ReadExact for T where T: Read + Sized {}