Read all entries (path, bytes) from a gzipped tar layer.
(tar_gz: &[u8])
| 328 | |
| 329 | /// Read all entries (path, bytes) from a gzipped tar layer. |
| 330 | fn read_layer_entries(tar_gz: &[u8]) -> Vec<(String, Vec<u8>)> { |
| 331 | let decoder = flate2::read::GzDecoder::new(tar_gz); |
| 332 | let mut archive = tar::Archive::new(decoder); |
| 333 | let mut out = Vec::new(); |
| 334 | for entry in archive.entries().unwrap() { |
| 335 | let mut entry = entry.unwrap(); |
| 336 | let path = entry.path().unwrap().to_string_lossy().into_owned(); |
| 337 | let mut bytes = Vec::new(); |
| 338 | entry.read_to_end(&mut bytes).unwrap(); |
| 339 | out.push((path, bytes)); |
| 340 | } |
| 341 | out |
| 342 | } |
| 343 | |
| 344 | #[test] |
| 345 | fn layer_from_dir_produces_valid_gzipped_tar() { |