从 C# 的 zip 文件中读取二进制文件而不解压缩
Read binary file from a zip file from C# without unzipping it
我想从 zip 文件中读取二进制文件而不解压缩它。
zip 文件结构:
zipFolderName/subFolder/BinFile
在 BinFile 中,我有:
Id1, id2, value1 // id1, id2 are string, value1 is int
在 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();
}
我收到错误:
无法读取超出流末尾的内容。
BinaryReader 似乎无法读取 MemoryStream ?
在 binFileName.Extract(ms);
之后尝试以下操作:
ms.Seek(0, SeekOrigin.Begin);
我想从 zip 文件中读取二进制文件而不解压缩它。
zip 文件结构:
zipFolderName/subFolder/BinFile
在 BinFile 中,我有:
Id1, id2, value1 // id1, id2 are string, value1 is int
在 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();
}
我收到错误: 无法读取超出流末尾的内容。 BinaryReader 似乎无法读取 MemoryStream ?
在 binFileName.Extract(ms);
之后尝试以下操作:
ms.Seek(0, SeekOrigin.Begin);