MCPcopy Create free account
hub / github.com/cosdata/cosdata / create_file

Function create_file

tests/benches/write_concurrent_benchmark.rs:8–35  ·  view source on GitHub ↗
(path: &str, size: u64)

Source from the content-addressed store, hash-verified

6use std::thread;
7
8fn create_file(path: &str, size: u64) -> std::io::Result<File> {
9 let mut file = OpenOptions::new()
10 .read(true)
11 .write(true)
12 .create(true)
13 .truncate(true)
14 .open(path)?;
15
16 let mut rng = rand::thread_rng();
17 const BUFFER_SIZE: usize = 8192; // 8 KB buffer
18 let mut buffer = [0u8; BUFFER_SIZE];
19
20 let full_chunks = size / BUFFER_SIZE as u64;
21 let remainder = (size % BUFFER_SIZE as u64) as usize;
22
23 for _ in 0..full_chunks {
24 rng.fill(&mut buffer[..]);
25 file.write_all(&buffer)?;
26 }
27
28 if remainder > 0 {
29 rng.fill(&mut buffer[..remainder]);
30 file.write_all(&buffer[..remainder])?;
31 }
32
33 file.seek(SeekFrom::Start(0))?; // Reset file pointer to the beginning
34 Ok(file)
35}
36
37fn write_random_bytes(
38 mut file: &File,

Callers 1

Calls 1

readMethod · 0.45

Tested by

no test coverage detected