我将名为Result
的字节数组压缩为zipped.dat
文件。
Using zip As Ionic.Zip.ZipFile = New Ionic.Zip.ZipFile
zip.AddEntry("Result", Result)
zip.Save("zipped.dat")
End Using
我想在运行时打开文件,获取zipped.dat
内容,最后取回我的Result
数组。
'Extract contain to Result array again
Dim Result() as byte = ...
答案 0 :(得分:1)
您可以使用" zipped.dat"解压缩这样的文件。对于zipPath和extractPath的目标文件夹:
Imports System.IO.Compression
...
ZipFile.ExtractToDirectory(zipPath, extractPath)
您可以提取类似这样的单个文件(未经测试):
Using archive As ZipArchive = ZipFile.OpenRead(zipPath)
entry = getentry(filename)
if entry isnot nothing then entry.ExtractToFile(Path.Combine(extractPath, entry.FullName))
End Using
要将其提取到流中,请使用:
Using archive As ZipArchive = ZipFile.OpenRead("c:\tmp\track.zip"),
entry = archive.GetEntry("track.gdb")
If entry IsNot Nothing Then
Using zStream As Stream = entry.Open()
Dim b As Byte
b = zStream.ReadByte()
End Using
End If
End Using
使用流,您可以将其读入内存。
答案 1 :(得分:0)
我很少修改xpda的答案。这对我现在很有用。感谢xpda
Dim data As New MemoryStream()
Dim archive As ZipArchive = ZipFile.OpenRead("zipped.dat")
Dim entry = archive.GetEntry("Result")
entry.Open.CopyTo(data)
Dim Result() As Byte = data.ToArray()