MCPcopy Create free account
hub / github.com/LibertyOS-Development/kernel / read_to_bytes

Function read_to_bytes

src/fs/mod.rs:344–369  ·  view source on GitHub ↗

Read to bytes

(path: &str)

Source from the content-addressed store, hash-verified

342
343// Read to bytes
344pub fn read_to_bytes(path: &str) -> Result<Vec<u8>, ()>
345{
346 if let Some(info) = crate::sys::sc::info(&path)
347 {
348 let res = if info.isdev()
349 {
350 dev_open(&path)
351 }
352 else
353 {
354 file_open(&path)
355 };
356
357 if let Some(handle) = res
358 {
359 let mut buffer = vec![0; info.size() as usize];
360 if let Some(bytes) = crate::sys::sc::read(handle, &mut buffer)
361 {
362 buffer.resize(bytes, 0);
363 crate::sys::sc::close(handle);
364 return Ok(buffer);
365 }
366 }
367 }
368 Err(())
369}
370
371
372// Read to string

Callers 1

read_to_strFunction · 0.85

Calls 7

dev_openFunction · 0.85
file_openFunction · 0.85
closeFunction · 0.85
isdevMethod · 0.80
infoFunction · 0.70
readFunction · 0.70
ErrEnum · 0.50

Tested by

no test coverage detected