use the header

This commit is contained in:
Mackenzie Clark
2019-03-14 13:32:47 -07:00
parent 93b602d8ea
commit 8fc2a13828
6 changed files with 70 additions and 3 deletions

View File

@ -1,3 +1,4 @@
use crate::vfs::vfs_header::{header_from_bytes, ArchiveType, CompressionType};
use std::collections::BTreeMap;
use std::io;
use std::io::Read;
@ -19,6 +20,14 @@ impl Vfs {
Vfs::from_tar_bytes(&decompressed_data[..])
}
pub fn from_compressed_bytes(compressed_data_slice: &[u8]) -> Result<Self, failure::Error> {
let data_bytes = &compressed_data_slice[4..];
match header_from_bytes(compressed_data_slice)? {
(_, CompressionType::ZSTD, ArchiveType::TAR) => Vfs::from_tar_zstd_bytes(data_bytes),
(_, CompressionType::NONE, ArchiveType::TAR) => Vfs::from_tar_bytes(data_bytes),
}
}
/// Create a vfs from raw bytes in tar format
pub fn from_tar_bytes<Reader: Read>(tar_bytes: Reader) -> Result<Self, failure::Error> {
let mut ar = tar::Archive::new(tar_bytes);