diff --git a/Cargo.toml b/Cargo.toml index 73eb769..7ec0973 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,6 @@ bufstream = { version = "0.1", optional = true } hostname = { version = "0.3", optional = true } hyperx = { version = "1", optional = true, features = ["headers"] } idna = "0.2" -line-wrap = "0.1" log = { version = "0.4", optional = true } mime = { version = "0.3", optional = true } native-tls = { version = "0.2", optional = true } diff --git a/src/message/encoder.rs b/src/message/encoder.rs index 9b6e377..11c4623 100644 --- a/src/message/encoder.rs +++ b/src/message/encoder.rs @@ -1,6 +1,4 @@ use crate::message::header::ContentTransferEncoding; -use line_wrap::{crlf, line_wrap, LineEnding}; -use std::io::Write; /// Encoder trait pub trait EncoderCodec: Send { @@ -93,13 +91,19 @@ impl EightBitCodec { impl EncoderCodec for EightBitCodec { fn encode(&mut self, input: &[u8]) -> Vec { - let ending = &crlf(); + let ending = b"\r\n"; + let endings_len = input.len() / self.max_length * ending.len(); + let mut out = Vec::with_capacity(input.len() + endings_len); - let mut out = vec![0_u8; input.len() + input.len() / self.max_length * ending.len()]; - let mut writer: &mut [u8] = out.as_mut(); - writer.write_all(input).unwrap(); + for chunk in input.chunks(self.max_length) { + // write the line ending after every chunk, except the last one + if !out.is_empty() { + out.extend_from_slice(ending); + } + + out.extend_from_slice(chunk); + } - line_wrap(&mut out, input.len(), self.max_length, ending); out } }