Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions crates/compression-codecs/src/gzip/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::io;

#[derive(Debug)]
enum State {
Header(PartialBuffer<Vec<u8>>),
Header(PartialBuffer<[u8; 10]>),
Encoding,
Footer(PartialBuffer<Vec<u8>>),
Footer(PartialBuffer<[u8; 8]>),
Done,
}

Expand All @@ -18,7 +18,7 @@ pub struct GzipEncoder {
state: State,
}

fn header(level: Compression) -> Vec<u8> {
fn header(level: Compression) -> [u8; 10] {
let level_byte = if level.level() >= Compression::best().level() {
0x02
} else if level.level() <= Compression::fast().level() {
Expand All @@ -27,7 +27,7 @@ fn header(level: Compression) -> Vec<u8> {
0x00
};

vec![0x1f, 0x8b, 0x08, 0, 0, 0, 0, 0, level_byte, 0xff]
[0x1f, 0x8b, 0x08, 0, 0, 0, 0, 0, level_byte, 0xff]
}

impl GzipEncoder {
Expand All @@ -39,11 +39,11 @@ impl GzipEncoder {
}
}

fn footer(&mut self) -> Vec<u8> {
let mut output = Vec::with_capacity(8);
fn footer(&mut self) -> [u8; 8] {
let mut output = [0; 8];

output.extend(&self.crc.sum().to_le_bytes());
output.extend(&self.crc.amount().to_le_bytes());
output[..4].copy_from_slice(&self.crc.sum().to_le_bytes());
output[4..].copy_from_slice(&self.crc.amount().to_le_bytes());

output
}
Expand Down