(
blob_path: &Path,
media_type: &str,
dest: &Path,
)
| 3793 | } |
| 3794 | |
| 3795 | fn extract_layer_blob_to_dir( |
| 3796 | blob_path: &Path, |
| 3797 | media_type: &str, |
| 3798 | dest: &Path, |
| 3799 | ) -> Result<(), String> { |
| 3800 | if dest.exists() { |
| 3801 | fs::remove_dir_all(dest).map_err(|err| format!("remove {}: {err}", dest.display()))?; |
| 3802 | } |
| 3803 | fs::create_dir_all(dest).map_err(|err| format!("create {}: {err}", dest.display()))?; |
| 3804 | |
| 3805 | let file = |
| 3806 | fs::File::open(blob_path).map_err(|err| format!("open {}: {err}", blob_path.display()))?; |
| 3807 | match layer_compression_from_media_type(media_type)? { |
| 3808 | LayerCompression::None => extract_tar_reader_to_dir(file, dest), |
| 3809 | LayerCompression::Gzip => extract_tar_reader_to_dir(GzDecoder::new(file), dest), |
| 3810 | LayerCompression::Zstd => { |
| 3811 | let decoder = zstd::stream::read::Decoder::new(file) |
| 3812 | .map_err(|err| format!("decompress {}: {err}", blob_path.display()))?; |
| 3813 | extract_tar_reader_to_dir(decoder, dest) |
| 3814 | } |
| 3815 | } |
| 3816 | } |
| 3817 | |
| 3818 | fn extract_tar_reader_to_dir(reader: impl Read, dest: &Path) -> Result<(), String> { |
| 3819 | let mut archive = tar::Archive::new(reader); |
no test coverage detected