tangled
alpha
login
or
join now
zachshipko.com
/
bindle-file
0
fork
atom
an efficient binary archive format
0
fork
atom
overview
issues
pulls
pipelines
Bindle::read_to
zachshipko.com
2 months ago
1b4a0b5d
180392bd
+25
1 changed file
expand all
collapse all
unified
split
src
lib.rs
+25
src/lib.rs
reviewed
···
437
437
}
438
438
}
439
439
440
440
+
pub fn read_to<W: std::io::Write>(&self, name: &str, mut w: W) -> std::io::Result<()> {
441
441
+
let entry = self
442
442
+
.index
443
443
+
.get(name)
444
444
+
.ok_or_else(|| io::Error::new(io::ErrorKind::InvalidData, "Invalid entry"))?;
445
445
+
let mmap = self
446
446
+
.mmap
447
447
+
.as_ref()
448
448
+
.ok_or_else(|| io::Error::new(io::ErrorKind::InvalidData, "Missing mmap"))?;
449
449
+
let data = mmap
450
450
+
.get(entry.offset() as usize..(entry.offset() + entry.compressed_size()) as usize)
451
451
+
.ok_or_else(|| io::Error::new(io::ErrorKind::InvalidData, "Invalid mmap offset"))?;
452
452
+
453
453
+
if entry.compression_type == 1 {
454
454
+
std::io::copy(
455
455
+
&mut zstd::Decoder::new(data)
456
456
+
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?,
457
457
+
&mut w,
458
458
+
)?;
459
459
+
} else {
460
460
+
w.write_all(&data)?;
461
461
+
}
462
462
+
Ok(())
463
463
+
}
464
464
+
440
465
/// The number of entries
441
466
pub fn len(&self) -> usize {
442
467
self.index.len()