From e08b5f3853784e2fb8dc016d4a149c1a2282f127 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Mon, 9 Feb 2026 22:58:16 +0000 Subject: feat: add initial implementation of rsli crate - Created Cargo.toml for the rsli crate with flate2 dependency. - Implemented ResourceData enum for handling borrowed and owned byte slices. - Added OutputBuffer trait and its Vec implementation for writing data. - Defined a comprehensive Error enum for error handling in the library. - Developed the Library struct to manage resource entries and provide methods for loading and unpacking resources. - Implemented various packing methods and decompression algorithms, including LZSS and Deflate. - Added tests for validating the functionality of the rsli library against sample data. --- crates/rsli/src/data.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 crates/rsli/src/data.rs (limited to 'crates/rsli/src/data.rs') diff --git a/crates/rsli/src/data.rs b/crates/rsli/src/data.rs new file mode 100644 index 0000000..daa5592 --- /dev/null +++ b/crates/rsli/src/data.rs @@ -0,0 +1,41 @@ +use std::io; + +#[derive(Clone, Debug)] +pub enum ResourceData<'a> { + Borrowed(&'a [u8]), + Owned(Vec), +} + +impl<'a> ResourceData<'a> { + pub fn as_slice(&self) -> &[u8] { + match self { + Self::Borrowed(slice) => slice, + Self::Owned(buf) => buf.as_slice(), + } + } + + pub fn into_owned(self) -> Vec { + match self { + Self::Borrowed(slice) => slice.to_vec(), + Self::Owned(buf) => buf, + } + } +} + +impl AsRef<[u8]> for ResourceData<'_> { + fn as_ref(&self) -> &[u8] { + self.as_slice() + } +} + +pub trait OutputBuffer { + fn write_exact(&mut self, data: &[u8]) -> io::Result<()>; +} + +impl OutputBuffer for Vec { + fn write_exact(&mut self, data: &[u8]) -> io::Result<()> { + self.clear(); + self.extend_from_slice(data); + Ok(()) + } +} -- cgit v1.2.3