MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / read_from

Method read_from

nodedb/src/storage/segment.rs:107–122  ·  view source on GitHub ↗

Read the footer from the end of a file.

(path: &Path)

Source from the content-addressed store, hash-verified

105
106 /// Read the footer from the end of a file.
107 pub fn read_from(path: &Path) -> crate::Result<Self> {
108 let mut file = std::fs::File::open(path)?;
109 let file_len = file.metadata()?.len() as usize;
110 if file_len < FOOTER_SIZE {
111 return Err(crate::Error::SegmentCorrupted {
112 detail: "file too small for segment footer".into(),
113 });
114 }
115
116 use std::io::Seek;
117 file.seek(std::io::SeekFrom::End(-(FOOTER_SIZE as i64)))?;
118 let mut buf = [0u8; FOOTER_SIZE];
119 file.read_exact(&mut buf)?;
120
121 Self::from_bytes(&buf)
122 }
123
124 /// Footer size in bytes.
125 pub const fn size() -> usize {

Callers

nothing calls this directly

Calls 3

openFunction · 0.50
lenMethod · 0.45
read_exactMethod · 0.45

Tested by

no test coverage detected