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
use libflate::deflate;
#[doc(hidden)]
pub use include_flate_codegen as codegen;
#[doc(hidden)]
pub use lazy_static::lazy_static;
#[macro_export]
macro_rules! flate {
($(pub $(($($vis:tt)+))?)? static $name:ident: [u8] from $path:literal) => {
$crate::lazy_static! {
$(pub $(($($vis)+))?)? static ref $name: ::std::vec::Vec<u8> = $crate::decode($crate::codegen::deflate_file!($path));
}
};
($(pub $(($($vis:tt)+))?)? static $name:ident: str from $path:literal) => {
$crate::lazy_static! {
$(pub $(($($vis)+))?)? static ref $name: ::std::string::String = $crate::decode_string($crate::codegen::deflate_utf8_file!($path));
}
};
}
#[doc(hidden)]
pub fn decode(bytes: &[u8]) -> Vec<u8> {
use std::io::{Cursor, Read};
let mut dec = deflate::Decoder::new(Cursor::new(bytes));
let mut ret = Vec::new();
dec.read_to_end(&mut ret).expect("Compiled DEFLATE buffer was corrupted");
ret
}
#[doc(hidden)]
pub fn decode_string(bytes: &[u8]) -> String {
String::from_utf8(decode(bytes)).expect("flate_str has malformed UTF-8 despite checked at compile time")
}