Read the footer from the end of a file.
(path: &Path)
| 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 { |
nothing calls this directly
no test coverage detected