1 extern crate flate2;
2
3 use std::io::{Read, Write};
4
5 #[test]
deflate_decoder_empty_read()6 fn deflate_decoder_empty_read() {
7 let original: &[u8] = b"Lorem ipsum dolor sit amet.";
8 let mut encoder =
9 flate2::write::DeflateEncoder::new(Vec::new(), flate2::Compression::default());
10 encoder.write_all(original).unwrap();
11 let encoded: Vec<u8> = encoder.finish().unwrap();
12 let mut decoder = flate2::read::DeflateDecoder::new(encoded.as_slice());
13 assert_eq!(decoder.read(&mut []).unwrap(), 0);
14 let mut decoded = Vec::new();
15 decoder.read_to_end(&mut decoded).unwrap();
16 assert_eq!(decoded.as_slice(), original);
17 }
18
19 #[test]
deflate_encoder_empty_read()20 fn deflate_encoder_empty_read() {
21 let original: &[u8] = b"Lorem ipsum dolor sit amet.";
22 let mut encoder = flate2::read::DeflateEncoder::new(original, flate2::Compression::default());
23 assert_eq!(encoder.read(&mut []).unwrap(), 0);
24 let mut encoded = Vec::new();
25 encoder.read_to_end(&mut encoded).unwrap();
26 let mut decoder = flate2::read::DeflateDecoder::new(encoded.as_slice());
27 let mut decoded = Vec::new();
28 decoder.read_to_end(&mut decoded).unwrap();
29 assert_eq!(decoded.as_slice(), original);
30 }
31
32 #[test]
gzip_decoder_empty_read()33 fn gzip_decoder_empty_read() {
34 let original: &[u8] = b"Lorem ipsum dolor sit amet.";
35 let mut encoder = flate2::write::GzEncoder::new(Vec::new(), flate2::Compression::default());
36 encoder.write_all(original).unwrap();
37 let encoded: Vec<u8> = encoder.finish().unwrap();
38 let mut decoder = flate2::read::GzDecoder::new(encoded.as_slice());
39 assert_eq!(decoder.read(&mut []).unwrap(), 0);
40 let mut decoded = Vec::new();
41 decoder.read_to_end(&mut decoded).unwrap();
42 assert_eq!(decoded.as_slice(), original);
43 }
44
45 #[test]
gzip_encoder_empty_read()46 fn gzip_encoder_empty_read() {
47 let original: &[u8] = b"Lorem ipsum dolor sit amet.";
48 let mut encoder = flate2::read::GzEncoder::new(original, flate2::Compression::default());
49 assert_eq!(encoder.read(&mut []).unwrap(), 0);
50 let mut encoded = Vec::new();
51 encoder.read_to_end(&mut encoded).unwrap();
52 let mut decoder = flate2::read::GzDecoder::new(encoded.as_slice());
53 let mut decoded = Vec::new();
54 decoder.read_to_end(&mut decoded).unwrap();
55 assert_eq!(decoded.as_slice(), original);
56 }
57
58 #[test]
zlib_decoder_empty_read()59 fn zlib_decoder_empty_read() {
60 let original: &[u8] = b"Lorem ipsum dolor sit amet.";
61 let mut encoder = flate2::write::ZlibEncoder::new(Vec::new(), flate2::Compression::default());
62 encoder.write_all(original).unwrap();
63 let encoded: Vec<u8> = encoder.finish().unwrap();
64 let mut decoder = flate2::read::ZlibDecoder::new(encoded.as_slice());
65 assert_eq!(decoder.read(&mut []).unwrap(), 0);
66 let mut decoded = Vec::new();
67 decoder.read_to_end(&mut decoded).unwrap();
68 assert_eq!(decoded.as_slice(), original);
69 }
70
71 #[test]
zlib_encoder_empty_read()72 fn zlib_encoder_empty_read() {
73 let original: &[u8] = b"Lorem ipsum dolor sit amet.";
74 let mut encoder = flate2::read::ZlibEncoder::new(original, flate2::Compression::default());
75 assert_eq!(encoder.read(&mut []).unwrap(), 0);
76 let mut encoded = Vec::new();
77 encoder.read_to_end(&mut encoded).unwrap();
78 let mut decoder = flate2::read::ZlibDecoder::new(encoded.as_slice());
79 let mut decoded = Vec::new();
80 decoder.read_to_end(&mut decoded).unwrap();
81 assert_eq!(decoded.as_slice(), original);
82 }
83