Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
tibvdm committed Apr 29, 2024
1 parent 29ae119 commit 76d5e4f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions bitarray/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::io::{stdin, stdout, BufReader, BufWriter, Read};

use bitarray::{binary::Binary, BitArray};

pub fn main() {
let stdin = stdin();
let stdout = stdout();

let mut reader = BufReader::new(stdin.lock());
let mut writer = BufWriter::new(stdout.lock());

let mut sample_rate_buffer = [0_u8; 1];
reader.read_exact(&mut sample_rate_buffer).map_err(|_| "Could not read the sample rate from the binary file").unwrap();

let mut bitarray = BitArray::<38>::with_capacity(30_000_000_000);

// this buffer is 1GiB big
let mut index = 0;
let mut buffer = [0; 8 * 1024];
let mut bytes_read = reader.read(&mut buffer).unwrap();
while bytes_read > 0 {
for buffer_slice in buffer.chunks_exact(8) {
bitarray.set(index, u64::from_le_bytes(buffer_slice.try_into().unwrap()));
index += 1;
}
bytes_read = reader.read(&mut buffer).unwrap();
}

bitarray.write_binary(&mut writer).unwrap();
}

0 comments on commit 76d5e4f

Please sign in to comment.