Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
295613c
Add tests that verify we handle unseekable streams correctly.
carlossanlop Apr 3, 2023
d627497
Add expected data field locations for all supported formats.
carlossanlop Apr 3, 2023
018f709
Add exception message for when attempting to write an unseekable data…
carlossanlop Apr 3, 2023
9092cb4
Add seekability validation in public TarWriter entry writing methods.
carlossanlop Apr 3, 2023
6c460eb
Add TarFile stream roundtrip tests for unseekable streams.
carlossanlop Apr 4, 2023
6ea8e0f
Add missing async TarFile roundtrip tests.
carlossanlop Apr 4, 2023
f87b9e9
Support unseekable streams in TarHeader.Write.
carlossanlop Apr 4, 2023
e94fefb
Reuse and simplify the code.
carlossanlop Apr 4, 2023
15523ac
More reuse, remove unused and not needed.
carlossanlop Apr 4, 2023
5979be9
Remove TarFile.CreateFromDirectoryAsync.File.Roundtrip.cs. Submit it …
carlossanlop Apr 4, 2023
b702a44
Remove unnecessary resx comments.
carlossanlop May 23, 2023
625a619
Dedicated method for writing fields to buffer depending on the format.
carlossanlop May 23, 2023
4f702c4
Specify `Data` in name of method that expects unseekable data stream.…
carlossanlop May 23, 2023
0054f99
Delete unnecessary method.
carlossanlop May 23, 2023
2fc23de
Rename WritePadding to WriteEmptyPadding
carlossanlop May 23, 2023
d81b5a8
Rename test variables
carlossanlop May 24, 2023
796d542
Merge identical test arrays into one
carlossanlop May 24, 2023
94157b0
Invert if else to be more clear about conditions
carlossanlop May 24, 2023
1557885
remove size assign comment
carlossanlop May 24, 2023
943988b
Remove redundant debug assert
carlossanlop May 24, 2023
abff5c0
Async padding byte array creation simplification
carlossanlop May 24, 2023
66dc094
Apply suggestions from code review
adamsitnik May 25, 2023
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
Prev Previous commit
Next Next commit
Delete unnecessary method.
  • Loading branch information
carlossanlop committed May 23, 2023
commit 0054f990c495f69286bb8809bb44aab45aa0107b
Original file line number Diff line number Diff line change
Expand Up @@ -171,42 +171,6 @@ private void WriteV7FieldsToBuffer(long size, Span<byte> buffer)
_checksum = WriteChecksum(tmpChecksum, buffer);
}

// Asynchronously writes the entry in the order required to be able to obtain the unseekable data stream size.
private async Task WriteAsUstarWithUnseekableDataStreamAsync(Stream archiveStream, Memory<byte> buffer, CancellationToken cancellationToken)
{
// When the data stream is unseekable, the order in which we write the entry data changes
Debug.Assert(archiveStream.CanSeek);
Debug.Assert(_dataStream != null);

// Store the start of the current entry's header, it'll be used later
long headerStartPosition = archiveStream.Position;

// We know the exact location where the data starts depending on the format
long dataStartPosition = headerStartPosition + FieldLocations.PosixData;

// Move to the data start location and write the data
archiveStream.Seek(FieldLocations.PosixData, SeekOrigin.Current);
await _dataStream.CopyToAsync(archiveStream, cancellationToken).ConfigureAwait(false); // The data gets copied from the current position

// Get the new archive stream position, and the difference is the size of the data stream
long dataEndPosition = archiveStream.Position;
long actualLength = dataEndPosition - dataStartPosition;

// Write the padding now so that we can go back to writing the entry's header metadata
await WritePaddingAsync(archiveStream, actualLength, cancellationToken).ConfigureAwait(false);

// Store the end of the current header, we will write the next one after this position
long endOfHeaderPosition = archiveStream.Position;

// Go back to the start of the entry header to write the rest of the fields
archiveStream.Position = headerStartPosition;
WriteUstarFieldsToBuffer(actualLength, buffer.Span);
await archiveStream.WriteAsync(buffer, cancellationToken).ConfigureAwait(false);

// Finally, move to the end of the header to continue with the next entry
archiveStream.Position = endOfHeaderPosition;
}

// Writes the Ustar header fields to the specified buffer, calculates and writes the checksum, then returns the final data length.
private void WriteUstarFieldsToBuffer(long size, Span<byte> buffer)
{
Expand Down