Skip to content

Commit 0f746e5

Browse files
committed
no bytealign unless catable, appendable, or bare
1 parent c44ecc7 commit 0f746e5

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/enc/backward_references/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ pub struct BrotliEncoderParams {
9191
pub large_window: bool,
9292
// avoid search for the best ndirect vs npostfix parameters for distance
9393
pub avoid_distance_prefix_search: bool,
94-
// insert empty metadata blocks before and after the compressed data
95-
// this allows for concatonation by byte copying with catable/appendable
94+
// inserts an extra empty metadata block before the final empty metablock in
95+
// catable/appendable mode so concatination tools can just remove the last byte
9696
pub byte_align: bool,
9797
// do not emit a stream header or empty last block at end of data
9898
pub bare_stream: bool,

src/enc/encode.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ pub fn SanitizeParams(params: &mut BrotliEncoderParams) {
639639
}
640640
if params.bare_stream {
641641
params.byte_align = true;
642+
} else if !params.appendable {
643+
params.byte_align = false;
642644
}
643645
}
644646

@@ -2268,16 +2270,8 @@ fn EncodeData<Alloc: BrotliAlloc,
22682270
}
22692271
let mut catable_header_size = 0;
22702272
if let IsFirst::NothingWritten = s.is_first_mb {
2271-
if s.params.magic_number || (s.params.byte_align && !s.params.catable && !s.params.appendable && !s.params.bare_stream) {
2272-
if s.params.magic_number {
2273-
BrotliWriteMetadataMetaBlock(&s.params, &mut storage_ix, (*s).storage_.slice_mut());
2274-
} else {
2275-
// magic and catable have their own headers that cause byte alignment,
2276-
// and aligning the compressed data is pointless in appendable mode, so
2277-
// in those cases we don't need to force it here
2278-
BrotliStoreSyncMetaBlock(&mut storage_ix, (*s).storage_.slice_mut());
2279-
}
2280-
// XXX What does this do?
2273+
if s.params.magic_number {
2274+
BrotliWriteMetadataMetaBlock(&s.params, &mut storage_ix, (*s).storage_.slice_mut());
22812275
(*s).last_bytes_ = (*s).storage_.slice()[((storage_ix >> 3i32) as (usize))] as u16 | (
22822276
((*s).storage_.slice()[1 + ((storage_ix >> 3i32) as (usize))] as u16)<<8);
22832277
(*s).last_bytes_bits_ = (storage_ix & 7u32 as (usize)) as (u8);

0 commit comments

Comments
 (0)