Skip to content

Commit

Permalink
Rename to shared-brotli-patch-decoder and add a basic README.
Browse files Browse the repository at this point in the history
  • Loading branch information
garretrieger committed Oct 4, 2024
1 parent 1bfb66b commit d0021c8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ members = [
"fauntlet",
"klippa",
"fuzz",
"shared-brotli",
"shared-brotli-patch-decoder",
]

[workspace.package]
Expand Down Expand Up @@ -45,7 +45,7 @@ read-fonts = { version = "0.22.3", path = "read-fonts", default-features = false
# shaping support
skrifa = { version = "0.22.3", path = "skrifa", default-features = false, features = ["std"] }
write-fonts = { version = "0.29.0", path = "write-fonts" }
shared-brotli = { version = "0.1.0", path = "shared-brotli" }
shared-brotli-patch-decoder = { version = "0.1.0", path = "shared-brotli-patch-decoder" }

[workspace.metadata.release]
allow-branch = ["main"]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "shared-brotli"
name = "shared-brotli-patch-decoder"
version = "0.1.0"
description = "Wrapper around brotli-sys which allows for decoding shared brotli (https://datatracker.ietf.org/doc/draft-vandevenne-shared-brotli-format/) encoded data."
description = "Wrapper around brotli-sys which allows for decoding shared brotli (https://datatracker.ietf.org/doc/draft-vandevenne-shared-brotli-format/) encoded patch data."
edition.workspace = true
license.workspace = true
repository.workspace = true
Expand Down
6 changes: 6 additions & 0 deletions shared-brotli-patch-decoder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Shared Brotli Patch Decoder

This crate provides a wrapper around brotlic-sys to provide a method for decoding brotli encoded data which utilizes a shared raw
LZ77 dictionary. This is an extension to standard brotli decoding, which is specified here: https://datatracker.ietf.org/doc/html/draft-vandevenne-shared-brotli-format-11#section-3.2

This is meant to primarily be used in the context of decoding incremental font transfer patches (see: https://w3c.github.io/IFT/Overview.html#table-keyed).
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl std::error::Error for DecodeError {}
pub fn shared_brotli_decode(
encoded: &[u8],
shared_dictionary: Option<&[u8]>,
max_uncompressed_length: u32,
max_uncompressed_length: usize,
) -> Result<Vec<u8>, DecodeError> {
let decoder = unsafe { BrotliDecoderCreateInstance(None, None, ptr::null_mut()) };
if decoder.is_null() {
Expand All @@ -70,7 +70,7 @@ pub fn shared_brotli_decode(
}
}

let mut sink = vec![0u8; max_uncompressed_length as usize];
let mut sink = vec![0u8; max_uncompressed_length];

let mut next_in = encoded.as_ptr();
let mut available_in = encoded.len();
Expand Down Expand Up @@ -159,11 +159,7 @@ mod tests {
fn brotli_decode_with_shared_dict() {
assert_eq!(
Ok(TARGET.to_vec()),
shared_brotli_decode(
&SHARED_DICT_PATCH,
Some(BASE.as_bytes()),
TARGET.len() as u32,
)
shared_brotli_decode(&SHARED_DICT_PATCH, Some(BASE.as_bytes()), TARGET.len(),)
);
}

Expand All @@ -173,37 +169,29 @@ mod tests {

assert_eq!(
Ok(TARGET.to_vec()),
shared_brotli_decode(&NO_DICT_PATCH, None, TARGET.len() as u32)
shared_brotli_decode(&NO_DICT_PATCH, None, TARGET.len())
);

// Check that empty base is handled the same as no base.
assert_eq!(
Ok(TARGET.to_vec()),
shared_brotli_decode(&NO_DICT_PATCH, Some(base), TARGET.len() as u32)
shared_brotli_decode(&NO_DICT_PATCH, Some(base), TARGET.len())
);
}

#[test]
fn brotli_decode_too_little_output() {
assert_eq!(
Err(DecodeError::MaxSizeExceeded),
shared_brotli_decode(
&SHARED_DICT_PATCH,
Some(BASE.as_bytes()),
(TARGET.len() - 1) as u32
)
shared_brotli_decode(&SHARED_DICT_PATCH, Some(BASE.as_bytes()), TARGET.len() - 1)
);
}

#[test]
fn brotli_decode_excess_output() {
assert_eq!(
Ok(TARGET.to_vec()),
shared_brotli_decode(
&SHARED_DICT_PATCH,
Some(BASE.as_bytes()),
(TARGET.len() + 1) as u32,
)
shared_brotli_decode(&SHARED_DICT_PATCH, Some(BASE.as_bytes()), TARGET.len() + 1,)
);
}

Expand All @@ -214,7 +202,7 @@ mod tests {

assert_eq!(
Err(DecodeError::ExcessInputData),
shared_brotli_decode(&patch, None, TARGET.len() as u32)
shared_brotli_decode(&patch, None, TARGET.len())
);
}

Expand All @@ -224,7 +212,7 @@ mod tests {
let patch: Vec<u8> = NO_DICT_PATCH[..NO_DICT_PATCH.len() - 1].to_vec();
assert_eq!(
Err(DecodeError::InvalidStream),
shared_brotli_decode(&patch, None, TARGET.len() as u32)
shared_brotli_decode(&patch, None, TARGET.len())
);
}

Expand Down

0 comments on commit d0021c8

Please sign in to comment.