Skip to content

tests/builders/publish: Simplify files() fn #6909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions src/tests/builders/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crates_io::views::krate_publish as u;
use std::collections::BTreeMap;

use crates_io_tarball::TarballBuilder;
use flate2::{write::GzEncoder, Compression};

use super::DependencyBuilder;

Expand Down Expand Up @@ -49,20 +48,14 @@ impl PublishBuilder {
}

/// Set the files in the crate's tarball.
pub fn files(mut self, files: &[(&str, &[u8])]) -> Self {
let mut tarball = Vec::new();
{
let mut ar = tar::Builder::new(GzEncoder::new(&mut tarball, Compression::default()));
for (name, data) in files {
let mut header = tar::Header::new_gnu();
header.set_size(data.len() as u64);
assert_ok!(ar.append_data(&mut header, name, *data));
}
assert_ok!(ar.finish());
pub fn files(self, files: &[(&str, &[u8])]) -> Self {
let mut builder = TarballBuilder::new(&self.krate_name, &self.version.to_string());

for (name, data) in files {
builder = builder.add_file(name, data);
}

self.tarball = tarball;
self
self.tarball(builder.build())
}

/// Set the tarball directly to the given Vec of bytes
Expand Down