OpenEntryStream returns empty stream #475

Open
opened 2026-01-29 22:12:38 +00:00 by claunia · 2 comments
Owner

Originally created by @nikoslyk203 on GitHub (Sep 21, 2021).

I have downloaded a zip file as a stream through HttpClient in C# and I am trying to open one of the files inside the archive as a stream but for some reason when I use OpenEntryStream the stream returned is empty. Am I doing something wrong? The Zip File isn't corrupted because I tried to unzip the files to my disk and it did it successfully.

var zipRequest = httpClient.GetAsync(url).Result;
using (var zipStream = zipRequest.Content.ReadAsStreamAsync().Result)
using (var archive = SharpCompress.Archives.Zip.ZipArchive.Open(zipStream))
using (var xlsFileStream = archive.Entries.Where(x => x.Key == fileName).FirstOrDefault().OpenEntryStream())
{

}
Originally created by @nikoslyk203 on GitHub (Sep 21, 2021). I have downloaded a zip file as a stream through HttpClient in C# and I am trying to open one of the files inside the archive as a stream but for some reason when I use OpenEntryStream the stream returned is empty. Am I doing something wrong? The Zip File isn't corrupted because I tried to unzip the files to my disk and it did it successfully. ``` var zipRequest = httpClient.GetAsync(url).Result; using (var zipStream = zipRequest.Content.ReadAsStreamAsync().Result) using (var archive = SharpCompress.Archives.Zip.ZipArchive.Open(zipStream)) using (var xlsFileStream = archive.Entries.Where(x => x.Key == fileName).FirstOrDefault().OpenEntryStream()) { } ```
claunia added the question label 2026-01-29 22:12:38 +00:00
Author
Owner

@adamhathcock commented on GitHub (Sep 24, 2021):

Archives expect a random access stream. I don't know what HttpClient is doing with the response stream of that but it could not be buffered.

You should use Reader or buffer the stream yourself (to memory or a file) and see what happens.

Also, use async/await instead of .Result

@adamhathcock commented on GitHub (Sep 24, 2021): Archives expect a random access stream. I don't know what HttpClient is doing with the response stream of that but it could not be buffered. You should use Reader or buffer the stream yourself (to memory or a file) and see what happens. Also, use async/await instead of .Result
Author
Owner

@majorro commented on GitHub (Dec 11, 2024):

Same here, ReadAsStream returns MemoryStream btw

@majorro commented on GitHub (Dec 11, 2024): Same here, `ReadAsStream` returns `MemoryStream` btw
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#475