Skip to content

Commit c44ecc7

Browse files
committed
add option for bare stream
1 parent 34182ee commit c44ecc7

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

src/bin/brotli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,10 @@ fn main() {
528528
params.byte_align = true;
529529
continue;
530530
}
531+
if (argument == "-bare" || argument == "--bare") && !double_dash {
532+
params.bare_stream = true;
533+
continue;
534+
}
531535
if (argument == "-appendable" || argument == "--appendable") && !double_dash {
532536
params.appendable = true;
533537
continue;

src/enc/backward_references/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ pub struct BrotliEncoderParams {
9494
// insert empty metadata blocks before and after the compressed data
9595
// this allows for concatonation by byte copying with catable/appendable
9696
pub byte_align: bool,
97+
// do not emit a stream header or empty last block at end of data
98+
pub bare_stream: bool,
9799
// construct brotli in such a way that it may be concatenated with another brotli file using appropriate bit ops
98100
pub catable: bool,
99101
// can use the dictionary (default yes unless catable is set)

src/enc/encode.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,13 @@ value: u32) -> i32 {
345345
params.byte_align = value != 0;
346346
return 1i32;
347347
}
348+
if p as (i32) == BrotliEncoderParameter::BROTLI_PARAM_BARE_STREAM as (i32) {
349+
params.bare_stream = value != 0;
350+
if !params.byte_align {
351+
params.byte_align = value != 0;
352+
}
353+
return 1i32;
354+
}
348355
0i32
349356
}
350357

@@ -403,6 +410,7 @@ pub fn BrotliEncoderInitParams() -> BrotliEncoderParams {
403410
prior_bitmask_detection: 0,
404411
literal_adaptation: [(0,0);4],
405412
byte_align: false,
413+
bare_stream: false,
406414
catable: false,
407415
use_dictionary: true,
408416
appendable: false,
@@ -627,7 +635,10 @@ pub fn SanitizeParams(params: &mut BrotliEncoderParams) {
627635
}
628636
}
629637
if params.catable {
630-
params.appendable = true;
638+
params.appendable = true;
639+
}
640+
if params.bare_stream {
641+
params.byte_align = true;
631642
}
632643
}
633644

@@ -727,7 +738,9 @@ fn EnsureInitialized<Alloc: BrotliAlloc>
727738
if (*s).params.quality == 0i32 || (*s).params.quality == 1i32 {
728739
lgwin = brotli_max_int(lgwin, 18i32);
729740
}
730-
EncodeWindowBits(lgwin, s.params.large_window, &mut (*s).last_bytes_, &mut (*s).last_bytes_bits_);
741+
if !(*s).params.bare_stream {
742+
EncodeWindowBits(lgwin, s.params.large_window, &mut (*s).last_bytes_, &mut (*s).last_bytes_bits_);
743+
}
731744
}
732745
if (*s).params.quality == 0i32 {
733746
InitCommandPrefixCodes(&mut (*s).cmd_depths_[..],
@@ -2020,7 +2033,9 @@ fn WriteMetaBlockInternal<Alloc: BrotliAlloc,
20202033
if params.byte_align && ((*storage_ix & 7u32 as (usize)) != 0) {
20212034
BrotliStoreSyncMetaBlock(storage_ix, storage);
20222035
}
2023-
BrotliWriteEmptyLastMetaBlock(storage_ix, storage)
2036+
if !params.bare_stream {
2037+
BrotliWriteEmptyLastMetaBlock(storage_ix, storage)
2038+
}
20242039
}
20252040
return;
20262041
}
@@ -2164,7 +2179,9 @@ fn WriteMetaBlockInternal<Alloc: BrotliAlloc,
21642179
if params.byte_align && ((*storage_ix & 7u32 as (usize)) != 0) {
21652180
BrotliStoreSyncMetaBlock(storage_ix, storage);
21662181
}
2167-
BrotliWriteEmptyLastMetaBlock(storage_ix, storage)
2182+
if !params.bare_stream {
2183+
BrotliWriteEmptyLastMetaBlock(storage_ix, storage)
2184+
}
21682185
}
21692186
}
21702187

@@ -2251,7 +2268,7 @@ fn EncodeData<Alloc: BrotliAlloc,
22512268
}
22522269
let mut catable_header_size = 0;
22532270
if let IsFirst::NothingWritten = s.is_first_mb {
2254-
if s.params.magic_number || (s.params.byte_align && !s.params.catable && !s.params.appendable) {
2271+
if s.params.magic_number || (s.params.byte_align && !s.params.catable && !s.params.appendable && !s.params.bare_stream) {
22552272
if s.params.magic_number {
22562273
BrotliWriteMetadataMetaBlock(&s.params, &mut storage_ix, (*s).storage_.slice_mut());
22572274
} else {

src/enc/parameters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub enum BrotliEncoderParameter {
3030
BROTLI_PARAM_NO_DICTIONARY = 170,
3131
BROTLI_PARAM_FAVOR_EFFICIENCY = 171,
3232
BROTLI_PARAM_BYTE_ALIGN = 172,
33+
BROTLI_PARAM_BARE_STREAM = 173,
3334
UNUSED7=7,
3435
UNUSED8=8,
3536
UNUSED9=9,
@@ -173,7 +174,6 @@ pub enum BrotliEncoderParameter {
173174
UNUSED147=147,
174175
UNUSED148=148,
175176
UNUSED149=149,
176-
UNUSED173=173,
177177
UNUSED174=174,
178178
UNUSED175=175,
179179
UNUSED176=176,

0 commit comments

Comments
 (0)