问题
I would like to read a binary file from a zip file without unzipping it .
The zip file structure:
zipFolderName/subFolder/BinFile
In the BinFile, I have:
Id1, id2, value1 // id1, id2 are string, value1 is int
In C#:
ZipEntry binFileName = …; // it has been got from zipFile entries
MemoryStream ms = new MemoryStream();
binFileName.Extract(ms);
using (BinaryReader reader = new BinaryReader(ms))
{
string id1 = reader.ReadString(); // error popped here
string id2 = reader.ReadString();
int value1 = reader.ReadInt32();
}
I got error: Unable to read beyond the end of the stream. It seems that BinaryReader cannnot read MemoryStream ?
回答1:
After binFileName.Extract(ms);
try the following:
ms.Seek(0, SeekOrigin.Begin);
来源:https://stackoverflow.com/questions/43874834/read-binary-file-from-a-zip-file-from-c-sharp-without-unzipping-it