-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.rs
41 lines (37 loc) · 1.02 KB
/
build.rs
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
use liblzma::write::XzEncoder;
use std::fs::OpenOptions;
use std::io::Write;
fn main() {
let source = std::str::from_utf8(include_bytes!("src/source.txt")).unwrap();
let data: Vec<u8> = source
.split("\n\n")
.flat_map(|frame| {
frame.lines().map(|line| {
line.chars()
.collect::<Vec<char>>()
.chunks(8).map(|chunk| {
let mut n: u8 = 0;
for c in chunk {
n <<= 1;
if *c == '#' {
n += 1;
}
};
n
})
.collect::<Vec<u8>>()
})
.collect::<Vec<Vec<u8>>>()
})
.flatten()
.collect();
let file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open("src/source.bin")
.unwrap();
XzEncoder::new(file, 9)
.write_all(&data)
.unwrap();
}