Debian Codegraph @

debian/missing-sources/flate2/src/deflate/mod.rs

raw symbols SCIP
1 pub mod bufreadrust-analyzer cargo flate2 1.1.8 deflate/bufread/;
2 pub mod readrust-analyzer cargo flate2 1.1.8 deflate/read/;
3 pub mod writerust-analyzer cargo flate2 1.1.8 deflate/write/;
4
5 #[cfg(test)]
6 mod tests {
7 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::preluderust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/prelude/::*;
8
9 use rand::{rng, Rng};
10
11 use superrust-analyzer cargo flate2 1.1.8 crate/::{readrust-analyzer cargo flate2 1.1.8 read/, writerust-analyzer cargo flate2 1.1.8 write/};
12 use craterust-analyzer cargo flate2 1.1.8 crate/::Compressionrust-analyzer cargo flate2 1.1.8 Compression#;
13
14 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
15 fn roundtrip() {
16 let mut real = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new();
17 let mut w = writerust-analyzer cargo flate2 1.1.8 deflate/write/::DeflateEncoderrust-analyzer cargo flate2 1.1.8 deflate/write/DeflateEncoder#::new(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new(), Compression::default());
18 let v = craterust-analyzer cargo flate2 1.1.8 crate/::random_bytes().take(1024).collect::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
19 for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#200 {
20 let to_write = &v[..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#rng().random_range(0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#v.len())];
21 real.extend(to_write.iter().copied());
22 w.write_all(to_write).unwrap();
23 }
24 let result = w.finish().unwrap();
25 let mut r = readrust-analyzer cargo flate2 1.1.8 deflate/read/::DeflateDecoderrust-analyzer cargo flate2 1.1.8 deflate/read/DeflateDecoder#::new(&result[..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]);
26 let mut ret = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new();
27 r.read_to_end(&mut ret).unwrap();
28 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ret, real);
29 }
30
31 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
32 fn drop_writes() {
33 let mut data = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new();
34 writerust-analyzer cargo flate2 1.1.8 deflate/write/::DeflateEncoderrust-analyzer cargo flate2 1.1.8 deflate/write/DeflateEncoder#::new(&mut data, Compression::default())
35 .write_all(b"foo")
36 .unwrap();
37 let mut r = readrust-analyzer cargo flate2 1.1.8 deflate/read/::DeflateDecoderrust-analyzer cargo flate2 1.1.8 deflate/read/DeflateDecoder#::new(&data[..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]);
38 let mut ret = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new();
39 r.read_to_end(&mut ret).unwrap();
40 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ret, b"foo");
41 }
42
43 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
44 fn total_in() {
45 let mut real = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new();
46 let mut w = writerust-analyzer cargo flate2 1.1.8 deflate/write/::DeflateEncoderrust-analyzer cargo flate2 1.1.8 deflate/write/DeflateEncoder#::new(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new(), Compression::default());
47 let v = craterust-analyzer cargo flate2 1.1.8 crate/::random_bytes().take(1024).collect::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
48 for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#200 {
49 let to_write = &v[..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#rng().random_range(0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#v.len())];
50 real.extend(to_write.iter().copied());
51 w.write_all(to_write).unwrap();
52 }
53 let mut result = w.finish().unwrap();
54
55 let result_len = result.len();
56
57 for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#200 {
58 result.extend(v.iter().copied());
59 }
60
61 let mut r = readrust-analyzer cargo flate2 1.1.8 deflate/read/::DeflateDecoderrust-analyzer cargo flate2 1.1.8 deflate/read/DeflateDecoder#::new(&result[..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]);
62 let mut ret = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new();
63 r.read_to_end(&mut ret).unwrap();
64 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ret, real);
65 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(r.total_in(), result_len as u64);
66 }
67
68 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
69 fn roundtrip2() {
70 let v = craterust-analyzer cargo flate2 1.1.8 crate/::random_bytes().take(1024 * 1024).collect::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
71 let mut r =
72 readrust-analyzer cargo flate2 1.1.8 deflate/read/::DeflateDecoderrust-analyzer cargo flate2 1.1.8 deflate/read/DeflateDecoder#::new(readrust-analyzer cargo flate2 1.1.8 deflate/read/::DeflateEncoderrust-analyzer cargo flate2 1.1.8 deflate/read/DeflateEncoder#::new(&v[..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#], Compression::default()));
73 let mut ret = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new();
74 r.read_to_end(&mut ret).unwrap();
75 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ret, v);
76 }
77
78 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
79 fn roundtrip3() {
80 let v = craterust-analyzer cargo flate2 1.1.8 crate/::random_bytes().take(1024 * 1024).collect::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
81 let mut w = writerust-analyzer cargo flate2 1.1.8 deflate/write/::DeflateEncoderrust-analyzer cargo flate2 1.1.8 deflate/write/DeflateEncoder#::new(
82 writerust-analyzer cargo flate2 1.1.8 deflate/write/::DeflateDecoderrust-analyzer cargo flate2 1.1.8 deflate/write/DeflateDecoder#::new(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new()),
83 Compression::default(),
84 );
85 w.write_all(&v).unwrap();
86 let w = w.finish().unwrap().finish().unwrap();
87 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(w, v);
88 }
89
90 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
91 fn reset_writer() {
92 let v = craterust-analyzer cargo flate2 1.1.8 crate/::random_bytes().take(1024 * 1024).collect::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
93 let mut w = writerust-analyzer cargo flate2 1.1.8 deflate/write/::DeflateEncoderrust-analyzer cargo flate2 1.1.8 deflate/write/DeflateEncoder#::new(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new(), Compression::default());
94 w.write_all(&v).unwrap();
95 let a = w.reset(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new()).unwrap();
96 w.write_all(&v).unwrap();
97 let b = w.finish().unwrap();
98
99 let mut w = writerust-analyzer cargo flate2 1.1.8 deflate/write/::DeflateEncoderrust-analyzer cargo flate2 1.1.8 deflate/write/DeflateEncoder#::new(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new(), Compression::default());
100 w.write_all(&v).unwrap();
101 let c = w.finish().unwrap();
102 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(a == b && b == c);
103 }
104
105 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
106 fn reset_reader() {
107 let v = craterust-analyzer cargo flate2 1.1.8 crate/::random_bytes().take(1024 * 1024).collect::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
108 let (mut a, mut b, mut c) = (Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new(), Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new(), Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new());
109 let mut r = readrust-analyzer cargo flate2 1.1.8 deflate/read/::DeflateEncoderrust-analyzer cargo flate2 1.1.8 deflate/read/DeflateEncoder#::new(&v[..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#], Compression::default());
110 r.read_to_end(&mut a).unwrap();
111 r.reset(&v[..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]);
112 r.read_to_end(&mut b).unwrap();
113
114 let mut r = readrust-analyzer cargo flate2 1.1.8 deflate/read/::DeflateEncoderrust-analyzer cargo flate2 1.1.8 deflate/read/DeflateEncoder#::new(&v[..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#], Compression::default());
115 r.read_to_end(&mut c).unwrap();
116 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(a == b && b == c);
117 }
118
119 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
120 fn reset_decoder() {
121 let v = craterust-analyzer cargo flate2 1.1.8 crate/::random_bytes().take(1024 * 1024).collect::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
122 let mut w = writerust-analyzer cargo flate2 1.1.8 deflate/write/::DeflateEncoderrust-analyzer cargo flate2 1.1.8 deflate/write/DeflateEncoder#::new(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new(), Compression::default());
123 w.write_all(&v).unwrap();
124 let data = w.finish().unwrap();
125
126 {
127 let (mut a, mut b, mut c) = (Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new(), Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new(), Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new());
128 let mut r = readrust-analyzer cargo flate2 1.1.8 deflate/read/::DeflateDecoderrust-analyzer cargo flate2 1.1.8 deflate/read/DeflateDecoder#::new(&data[..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]);
129 r.read_to_end(&mut a).unwrap();
130 r.reset(&data);
131 r.read_to_end(&mut b).unwrap();
132
133 let mut r = readrust-analyzer cargo flate2 1.1.8 deflate/read/::DeflateDecoderrust-analyzer cargo flate2 1.1.8 deflate/read/DeflateDecoder#::new(&data[..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]);
134 r.read_to_end(&mut c).unwrap();
135 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(a == b && b == c && c == v);
136 }
137
138 {
139 let mut w = writerust-analyzer cargo flate2 1.1.8 deflate/write/::DeflateDecoderrust-analyzer cargo flate2 1.1.8 deflate/write/DeflateDecoder#::new(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new());
140 w.write_all(&data).unwrap();
141 let a = w.reset(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new()).unwrap();
142 w.write_all(&data).unwrap();
143 let b = w.finish().unwrap();
144
145 let mut w = writerust-analyzer cargo flate2 1.1.8 deflate/write/::DeflateDecoderrust-analyzer cargo flate2 1.1.8 deflate/write/DeflateDecoder#::new(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new());
146 w.write_all(&data).unwrap();
147 let c = w.finish().unwrap();
148 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(a == b && b == c && c == v);
149 }
150 }
151
152 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
153 fn zero_length_read_with_data() {
154 let m = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![3u8; 128 * 1024 + 1];
155 let mut c = readrust-analyzer cargo flate2 1.1.8 deflate/read/::DeflateEncoderrust-analyzer cargo flate2 1.1.8 deflate/read/DeflateEncoder#::new(&m[..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#], Compression::default());
156
157 let mut result = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new();
158 c.read_to_end(&mut result).unwrap();
159
160 let mut d = readrust-analyzer cargo flate2 1.1.8 deflate/read/::DeflateDecoderrust-analyzer cargo flate2 1.1.8 deflate/read/DeflateDecoder#::new(&result[..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]);
161 let mut data = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new();
162 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(d.read(&mut data).unwrap(), 0);
163 }
164
165 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
166 fn qc_reader() {
167 ::quickcheck::quickcheck(testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test: as fn(_) -> _);
168
169 fn test(v: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> bool {
170 let mut r = readrust-analyzer cargo flate2 1.1.8 deflate/read/::DeflateDecoderrust-analyzer cargo flate2 1.1.8 deflate/read/DeflateDecoder#::new(readrust-analyzer cargo flate2 1.1.8 deflate/read/::DeflateEncoderrust-analyzer cargo flate2 1.1.8 deflate/read/DeflateEncoder#::new(
171 &v[..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#],
172 Compression::default(),
173 ));
174 let mut v2 = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new();
175 r.read_to_end(&mut v2).unwrap();
176 v == v2
177 }
178 }
179
180 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
181 fn qc_writer() {
182 ::quickcheck::quickcheck(testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test: as fn(_) -> _);
183
184 fn test(v: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> bool {
185 let mut w = writerust-analyzer cargo flate2 1.1.8 deflate/write/::DeflateEncoderrust-analyzer cargo flate2 1.1.8 deflate/write/DeflateEncoder#::new(
186 writerust-analyzer cargo flate2 1.1.8 deflate/write/::DeflateDecoderrust-analyzer cargo flate2 1.1.8 deflate/write/DeflateDecoder#::new(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::new()),
187 Compression::default(),
188 );
189 w.write_all(&v).unwrap();
190 v == w.finish().unwrap().finish().unwrap()
191 }
192 }
193 }