Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove the writer reference requirement #386

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions backhand-cli/src/bin/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ fn main() -> ExitCode {
}

// write new file
let mut output = File::create(&args.out).unwrap();
if let Err(e) = filesystem.write(&mut output) {
let output = File::create(&args.out).unwrap();
if let Err(e) = filesystem.write(output) {
println!("[!] {e}");
}
println!("[-] added file and wrote to {}", args.out.display());
Expand Down
2 changes: 1 addition & 1 deletion backhand/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[lib]
bench = false
bench = false
2 changes: 1 addition & 1 deletion backhand/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl<'a> DataWriter<'a> {

/// Compress the fragments that were under length, write to data, add to fragment table, clear
/// current fragment_bytes
pub fn finalize<W: Write + Seek>(&mut self, writer: &mut W) -> Result<(), BackhandError> {
pub fn finalize<W: Write + Seek>(&mut self, mut writer: W) -> Result<(), BackhandError> {
let start = writer.stream_position()?;
let cb = self.kind.compress(&self.fragment_bytes, self.fs_compressor, self.block_size)?;

Expand Down
17 changes: 7 additions & 10 deletions backhand/src/filesystem/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,7 @@ impl<'a, 'b, 'c> FilesystemWriter<'a, 'b, 'c> {
///
/// # Returns
/// (written populated [`SuperBlock`], total amount of bytes written including padding)
pub fn write<W: Write + Seek>(
&mut self,
mut w: &mut W,
) -> Result<(SuperBlock, u64), BackhandError> {
pub fn write<W: Write + Seek>(&mut self, mut w: W) -> Result<(SuperBlock, u64), BackhandError> {
let mut superblock =
SuperBlock::new(self.fs_compressor.id, Kind { inner: self.kind.inner.clone() });

Expand Down Expand Up @@ -609,7 +606,7 @@ impl<'a, 'b, 'c> FilesystemWriter<'a, 'b, 'c> {
Kind { inner: self.kind.inner.clone() },
);
metadata.write_all(&compression_opt_buf_out)?;
metadata.finalize(w)?;
metadata.finalize(&mut w)?;
}

let mut data_writer =
Expand All @@ -631,7 +628,7 @@ impl<'a, 'b, 'c> FilesystemWriter<'a, 'b, 'c> {
self.write_data(self.fs_compressor, self.block_size, &mut w, &mut data_writer)?;
info!("Writing Data Fragments");
// Compress fragments and write
data_writer.finalize(w)?;
data_writer.finalize(&mut w)?;

info!("Writing Other stuff");
let root = self.write_inode_dir(
Expand All @@ -652,15 +649,15 @@ impl<'a, 'b, 'c> FilesystemWriter<'a, 'b, 'c> {

info!("Writing Inodes");
superblock.inode_table = w.stream_position()?;
inode_writer.finalize(w)?;
inode_writer.finalize(&mut w)?;

info!("Writing Dirs");
superblock.dir_table = w.stream_position()?;
dir_writer.finalize(w)?;
dir_writer.finalize(&mut w)?;

info!("Writing Frag Lookup Table");
let (table_position, count) =
self.write_lookup_table(w, &data_writer.fragment_table, fragment::SIZE)?;
self.write_lookup_table(&mut w, &data_writer.fragment_table, fragment::SIZE)?;
superblock.frag_table = table_position;
superblock.frag_count = count;

Expand Down Expand Up @@ -760,7 +757,7 @@ impl<'a, 'b, 'c> FilesystemWriter<'a, 'b, 'c> {
/// ```
fn write_lookup_table<D: DekuWriter<deku::ctx::Endian>, W: Write + Seek>(
&self,
mut w: &mut W,
mut w: W,
table: &Vec<D>,
element_size: usize,
) -> Result<(u64, u32), BackhandError> {
Expand Down
4 changes: 2 additions & 2 deletions backhand/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl MetadataWriter {
Ok(())
}

pub fn finalize<W: Write + Seek>(&mut self, out: &mut W) -> Result<(), BackhandError> {
pub fn finalize<W: Write + Seek>(&mut self, mut out: W) -> Result<(), BackhandError> {
//add any remaining data
while !self.uncompressed_bytes.is_empty() {
self.add_block()?;
Expand All @@ -87,7 +87,7 @@ impl MetadataWriter {
// if uncompressed, set the highest bit of len
let len =
compressed_bytes.len() as u16 | if *compressed { 0 } else { 1 << (u16::BITS - 1) };
let mut writer = Writer::new(out);
let mut writer = Writer::new(&mut out);
len.to_writer(&mut writer, self.kind.inner.data_endian)?;
out.write_all(compressed_bytes)?;
}
Expand Down