MCPcopy Create free account
hub / github.com/PerroEngine/Perro / stream_file

Method stream_file

perro_source/io_stack/perro_assets/src/archive.rs:110–129  ·  view source on GitHub ↗

Stream a file (only works for uncompressed files)

(&self, path: &str)

Source from the content-addressed store, hash-verified

108
109 /// Get a direct slice (only works for uncompressed files)
110 pub fn get_file_slice(&self, path: &str) -> io::Result<&[u8]> {
111 let entry = self
112 .index
113 .get(path)
114 .ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "File not found"))?;
115
116 if entry.flags & FLAG_COMPRESSED != 0 {
117 return Err(io::Error::other(
118 "Cannot get slice of compressed file (use read_file)",
119 ));
120 }
121
122 let range = checked_entry_range(self.data.len(), entry)?;
123 Ok(&self.data[range])
124 }
125
126 /// Stream a file (only works for uncompressed files)
127 pub fn stream_file(&self, path: &str) -> io::Result<PerroAssetsFile> {
128 let entry = self
129 .index
130 .get(path)
131 .ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "File not found"))?;
132

Callers 1

stream_assetFunction · 0.80

Calls 4

checked_entry_rangeFunction · 0.85
cloneMethod · 0.80
getMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected