-
Notifications
You must be signed in to change notification settings - Fork 189
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
Add contiguous mode to the Builder #234
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps a more descriptive name like "skip_footer_section" or something like that could be used instead of "contiguous" too?
@@ -356,6 +363,14 @@ impl<W: Write> Builder<W> { | |||
self.finished = true; | |||
self.get_mut().write_all(&[0; 1024]) | |||
} | |||
|
|||
fn finalize(&mut self) -> io::Result<()> { | |||
if !self.contiguous { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since finish()
is a public method, I think that it might be best if this check is folded into there? That can just keep the documentation, though, that it is not required to be called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've introduced finalize
since I wanted to give the user the possibility to write the 'footer' section, as you can see in the example.
I could move the check to finish
and then create public method write_footer_section
. Then this:
let mut builder = tar::Builder::new(...);
builder.skip_footer_section(true);
builder.finish();
would have no effect and would need to be transformed into:
let mut builder = tar::Builder::new(...);
builder.skip_footer_section(true);
builder.write_footer_section();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think though that this implementation, as-is, doesn't work. If you call finish
it ignores the skip_footer_section
flag introduced here, which I think is a bug. I think it'd be fine to basically say that finish
is optional if skip_footer_section
is true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does work, please take a look at the example I've added to examples/
or even tests. But I see your point, I will rename contiguous
to skip_footer_section
and move
self.get_mut().write_all(&[0; 1024])
To new public method write_footer_section
. Would that work in your opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes while it works I think it's too confusing. I think adding a separate method makes sense. That way there's a flag to disable auto-inclusion of the footer and in that scenario you can either create a tar::Builder
at the end with the flag enabled or you can manually call the footer write.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps a more descriptive name like "skip_footer_section" or something like that could be used instead of "contiguous" too?
Indeed, skip_footer_section
sounds much more readable. I was checking various tar format descriptions and it seems there is no fancy name for this. The official documentation uses 'end-of-archive entry' which is too long I guess.
@@ -356,6 +363,14 @@ impl<W: Write> Builder<W> { | |||
self.finished = true; | |||
self.get_mut().write_all(&[0; 1024]) | |||
} | |||
|
|||
fn finalize(&mut self) -> io::Result<()> { | |||
if !self.contiguous { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've introduced finalize
since I wanted to give the user the possibility to write the 'footer' section, as you can see in the example.
I could move the check to finish
and then create public method write_footer_section
. Then this:
let mut builder = tar::Builder::new(...);
builder.skip_footer_section(true);
builder.finish();
would have no effect and would need to be transformed into:
let mut builder = tar::Builder::new(...);
builder.skip_footer_section(true);
builder.write_footer_section();
Closes #227
There are many ways to implement this. Here is my proposal, I'm open to any suggestions.