Skip to content

Commit 1596167

Browse files
committed
add option for bare stream
1 parent 25735a9 commit 1596167

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

src/bin/brotli.rs

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

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

+22-5
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_[..],
@@ -2024,7 +2037,9 @@ fn WriteMetaBlockInternal<Alloc: BrotliAlloc,
20242037
if params.byte_align && ((*storage_ix & 7u32 as (usize)) != 0) {
20252038
BrotliStoreSyncMetaBlock(storage_ix, storage);
20262039
}
2027-
BrotliWriteEmptyLastMetaBlock(storage_ix, storage)
2040+
if !params.bare_stream {
2041+
BrotliWriteEmptyLastMetaBlock(storage_ix, storage)
2042+
}
20282043
}
20292044
return;
20302045
}
@@ -2168,7 +2183,9 @@ fn WriteMetaBlockInternal<Alloc: BrotliAlloc,
21682183
if params.byte_align && ((*storage_ix & 7u32 as (usize)) != 0) {
21692184
BrotliStoreSyncMetaBlock(storage_ix, storage);
21702185
}
2171-
BrotliWriteEmptyLastMetaBlock(storage_ix, storage)
2186+
if !params.bare_stream {
2187+
BrotliWriteEmptyLastMetaBlock(storage_ix, storage)
2188+
}
21722189
}
21732190
}
21742191

@@ -2255,7 +2272,7 @@ fn EncodeData<Alloc: BrotliAlloc,
22552272
}
22562273
let mut catable_header_size = 0;
22572274
if let IsFirst::NothingWritten = s.is_first_mb {
2258-
if s.params.magic_number || (s.params.byte_align && !s.params.catable && !s.params.appendable) {
2275+
if s.params.magic_number || (s.params.byte_align && !s.params.catable && !s.params.appendable && !s.params.bare_stream) {
22592276
if s.params.magic_number {
22602277
BrotliWriteMetadataMetaBlock(&s.params, &mut storage_ix, (*s).storage_.slice_mut());
22612278
} else {

src/enc/parameters.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub enum BrotliEncoderParameter {
3131
BROTLI_PARAM_NO_DICTIONARY = 170,
3232
BROTLI_PARAM_FAVOR_EFFICIENCY = 171,
3333
BROTLI_PARAM_BYTE_ALIGN = 172,
34+
BROTLI_PARAM_BARE_STREAM = 173,
3435
UNUSED7=7,
3536
UNUSED8=8,
3637
UNUSED9=9,
@@ -174,7 +175,6 @@ pub enum BrotliEncoderParameter {
174175
UNUSED147=147,
175176
UNUSED148=148,
176177
UNUSED149=149,
177-
UNUSED173=173,
178178
UNUSED174=174,
179179
UNUSED175=175,
180180
UNUSED176=176,

0 commit comments

Comments
 (0)