From 2cfb42b594e282d9f758fa03df0fc5f61a52f9d3 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Sun, 2 Mar 2025 17:13:54 +0700 Subject: [PATCH] Function to add files from in-memory data --- src/builder.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/builder.rs b/src/builder.rs index 54413605..b2989da8 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -184,6 +184,22 @@ impl Builder { self.append(&header, data) } + /// Add a file entry to the archive. + /// + /// This function will create a header for a file of correct size, mode, and checksum. + pub fn append_file_data>( + &mut self, + path: P, + mode: u32, + data: &[u8], + ) -> io::Result<()> { + let mut header = Header::new_gnu(); + header.set_size(data.len() as u64); + header.set_mode(mode); + header.set_cksum(); + self.append_data(&mut header, path, data) + } + /// Adds a new entry to this archive and returns an [`EntryWriter`] for /// adding its contents. ///