Skip to content

Commit 42a3826

Browse files
committed
no bytealign unless catable, appendable, or bare
1 parent 1596167 commit 42a3826

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/enc/backward_references/mod.rs

+2-2
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

+4-10
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

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

0 commit comments

Comments
 (0)