Skip to content

Commit

Permalink
Rename public facing unpacker fn
Browse files Browse the repository at this point in the history
  • Loading branch information
FlareFlo committed Dec 29, 2023
1 parent e95389d commit 113e4c0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
23 changes: 21 additions & 2 deletions src/blk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use std::{

pub use ::zstd::dict::DecoderDictionary;
use cfg_if::cfg_if;
use color_eyre::eyre::{Context, ContextCompat};

Check warning on line 12 in src/blk/mod.rs

View workflow job for this annotation

GitHub Actions / lint

unused import: `Context`

Check warning on line 12 in src/blk/mod.rs

View workflow job for this annotation

GitHub Actions / lint

unused import: `ContextCompat`

Check warning on line 12 in src/blk/mod.rs

View workflow job for this annotation

GitHub Actions / lint

unused imports: `ContextCompat`, `Context`
use color_eyre::Report;

use crate::blk::{
file::FileType,
Expand All @@ -19,6 +21,7 @@ use crate::blk::{
use crate::blk::blk_structure::BlkField;
use crate::blk::blk_type::BlkType;
use crate::blk::util::blk_str;
use crate::vromf::BlkOutputFormat;

Check warning on line 24 in src/blk/mod.rs

View workflow job for this annotation

GitHub Actions / lint

unused import: `crate::vromf::BlkOutputFormat`

/// Decodes flat map of fields into the corresponding nested datastructure
mod blk_block_hierarchy;
Expand Down Expand Up @@ -91,7 +94,23 @@ fn test_parse_dir(
}

/// Highest-level function for unpacking one BLK explicitly, for direct low level control call [`parser::parse_blk`]
pub fn parse_file(
pub fn unpack_blk(mut file: Vec<u8>, dictionary: Option<&BlkDecoder>, nm: Option<Arc<NameMap>>) -> Result<BlkField, Report> {
let mut offset = 0;
let file_type = FileType::from_byte(file[0])?;
if file_type.is_zstd() {
if file_type == FileType::FAT_ZSTD { offset += 1 }; // FAT_ZSTD has a leading byte indicating that its unpacked form is of the FAT format
file = decode_zstd(file_type, &file, dictionary)?;
} else {
// uncompressed Slim and Fat files retain their initial magic bytes
offset = 1;
};

let parsed = parse_blk(&file[offset..], file_type.is_slim(), nm)?;
Ok(parsed)
}


pub(crate) fn test_parse_file(

Check warning on line 113 in src/blk/mod.rs

View workflow job for this annotation

GitHub Actions / lint

function `test_parse_file` is never used
mut file: Vec<u8>,
fd: Arc<BlkDecoder>,
shared_name_map: Option<Arc<NameMap>>,
Expand All @@ -109,7 +128,7 @@ pub fn parse_file(
serde_json::to_string(
&parse_blk(&file[offset..], file_type.is_slim(), shared_name_map).ok()?,
)
.unwrap(),
.unwrap(),
)
}

Expand Down
4 changes: 2 additions & 2 deletions src/blk/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{

use zstd::dict::DecoderDictionary;

use crate::blk::{file::FileType, make_strict_test, nm_file::NameMap, parse_file, parser::parse_blk, test_parse_dir, zstd::decode_zstd};
use crate::blk::{file::FileType, make_strict_test, nm_file::NameMap, test_parse_file, parser::parse_blk, test_parse_dir, zstd::decode_zstd};

// #[test]
// fn json_parity() {
Expand Down Expand Up @@ -102,7 +102,7 @@ fn test_all() {
let arced_fd = Arc::new(frame_decoder);
let out = pile
.into_iter()
.map(|file| parse_file(file.1, arced_fd.clone(), shared_name_map.clone()))
.map(|file| test_parse_file(file.1, arced_fd.clone(), shared_name_map.clone()))
.filter_map(|x| x)
.collect::<Vec<_>>();

Expand Down

0 comments on commit 113e4c0

Please sign in to comment.