|
1 | 1 | use crates_io::views::krate_publish as u;
|
2 |
| -use std::{collections::BTreeMap, io::Read}; |
| 2 | +use std::collections::BTreeMap; |
3 | 3 |
|
4 | 4 | use crates_io_tarball::TarballBuilder;
|
5 | 5 | use flate2::{write::GzEncoder, Compression};
|
@@ -51,31 +51,14 @@ impl PublishBuilder {
|
51 | 51 | }
|
52 | 52 |
|
53 | 53 | /// Set the files in the crate's tarball.
|
54 |
| - pub fn files(self, files: &[(&str, &[u8])]) -> Self { |
55 |
| - let mut slices = files.iter().map(|p| p.1).collect::<Vec<_>>(); |
56 |
| - let mut files = files |
57 |
| - .iter() |
58 |
| - .zip(&mut slices) |
59 |
| - .map(|(&(name, _), data)| { |
60 |
| - let len = data.len() as u64; |
61 |
| - (name, data as &mut dyn Read, len) |
62 |
| - }) |
63 |
| - .collect::<Vec<_>>(); |
64 |
| - |
65 |
| - self.files_with_io(&mut files) |
66 |
| - } |
67 |
| - |
68 |
| - /// Set the tarball from a Read trait object |
69 |
| - pub fn files_with_io(mut self, files: &mut [(&str, &mut dyn Read, u64)]) -> Self { |
| 54 | + pub fn files(mut self, files: &[(&str, &[u8])]) -> Self { |
70 | 55 | let mut tarball = Vec::new();
|
71 | 56 | {
|
72 | 57 | let mut ar = tar::Builder::new(GzEncoder::new(&mut tarball, Compression::default()));
|
73 |
| - for &mut (name, ref mut data, size) in files { |
| 58 | + for (name, data) in files { |
74 | 59 | let mut header = tar::Header::new_gnu();
|
75 |
| - assert_ok!(header.set_path(name)); |
76 |
| - header.set_size(size); |
77 |
| - header.set_cksum(); |
78 |
| - assert_ok!(ar.append(&header, data)); |
| 60 | + header.set_size(data.len() as u64); |
| 61 | + assert_ok!(ar.append_data(&mut header, name, *data)); |
79 | 62 | }
|
80 | 63 | assert_ok!(ar.finish());
|
81 | 64 | }
|
|
0 commit comments