1 | use crate::{encoder::compression::*, tags::CompressionMethod}; |
2 | use std::io::Write; |
3 | |
4 | /// The default algorithm which does not compress at all. |
5 | #[derive (Debug, Clone, Copy, PartialEq, Eq, Default)] |
6 | pub struct Uncompressed; |
7 | |
8 | impl Compression for Uncompressed { |
9 | const COMPRESSION_METHOD: CompressionMethod = CompressionMethod::None; |
10 | |
11 | fn get_algorithm(&self) -> Compressor { |
12 | Compressor::Uncompressed(*self) |
13 | } |
14 | } |
15 | |
16 | impl CompressionAlgorithm for Uncompressed { |
17 | fn write_to<W: Write>(&mut self, writer: &mut W, bytes: &[u8]) -> Result<u64, io::Error> { |
18 | writer.write(bytes).map(|byte_count: usize| byte_count as u64) |
19 | } |
20 | } |
21 | |
22 | #[cfg (test)] |
23 | mod tests { |
24 | use super::*; |
25 | use crate::encoder::compression::tests::TEST_DATA; |
26 | use std::io::Cursor; |
27 | |
28 | #[test ] |
29 | fn test_no_compression() { |
30 | let mut compressed_data = Vec::<u8>::new(); |
31 | let mut writer = Cursor::new(&mut compressed_data); |
32 | Uncompressed.write_to(&mut writer, TEST_DATA).unwrap(); |
33 | assert_eq!(TEST_DATA, compressed_data); |
34 | } |
35 | } |
36 | |