From 1b6a04ca5504955c571d1c97504fb45ea0befee4 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Mon, 8 Jan 2024 01:21:28 +0400 Subject: Initial vendor packages Signed-off-by: Valentin Popov --- .../tiff/src/encoder/compression/uncompressed.rs | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 vendor/tiff/src/encoder/compression/uncompressed.rs (limited to 'vendor/tiff/src/encoder/compression/uncompressed.rs') diff --git a/vendor/tiff/src/encoder/compression/uncompressed.rs b/vendor/tiff/src/encoder/compression/uncompressed.rs new file mode 100644 index 0000000..900426f --- /dev/null +++ b/vendor/tiff/src/encoder/compression/uncompressed.rs @@ -0,0 +1,37 @@ +use crate::{encoder::compression::*, tags::CompressionMethod}; +use std::io::Write; + +/// The default algorithm which does not compress at all. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub struct Uncompressed; + +impl Compression for Uncompressed { + const COMPRESSION_METHOD: CompressionMethod = CompressionMethod::None; + + fn get_algorithm(&self) -> Compressor { + Compressor::Uncompressed(*self) + } +} + +impl CompressionAlgorithm for Uncompressed { + fn write_to(&mut self, writer: &mut W, bytes: &[u8]) -> Result { + writer.write(bytes).map(|byte_count| byte_count as u64) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::encoder::compression::tests::TEST_DATA; + use std::io::Cursor; + + #[test] + fn test_no_compression() { + let mut compressed_data = Vec::::new(); + let mut writer = Cursor::new(&mut compressed_data); + Uncompressed::default() + .write_to(&mut writer, TEST_DATA) + .unwrap(); + assert_eq!(TEST_DATA, compressed_data); + } +} -- cgit v1.2.3