Try adding archiveStream.Position = 0 before extracting the files. (You can also use archiveStream.Seek).
TAR file not working with stream - .NET7
Hi,
I am following below link from Microsoft about new TAR assembly added in .NET7.
https://devblogs.microsoft.com/dotnet/announcing-dotnet-7-preview-4/#added-new-tar-apis
I try to replicate example specified against "We also offer variants that allow extracting from a stream or archiving into a stream:"
But it is throwing error "System.IO.EndOfStreamException: 'Unable to read beyond the end of the stream.'"
Below is my code.
string sourceDirectoryName = "D:\TarFileDemo\FolderContainingFiles";
string destinationDirectoryName = "D:\TarFileDemo\ExtractedFiles";
MemoryStream archiveStream = new MemoryStream();
TarFile.CreateFromDirectory(sourceDirectoryName, archiveStream, true);
TarFile.ExtractToDirectory(archiveStream, destinationDirectoryName, true);
Please confirm what's wrong with this code.