JBTALKS.CC
标题:
【疑问】GZipStream Magic Number Exception
[打印本页]
作者:
goodhermit95
时间:
2009-7-10 11:57 PM
标题:
【疑问】GZipStream Magic Number Exception
Dim bufferWrite As Byte()
Dim fsSource As FileStream
Dim fsDest As FileStream
Dim gzDeCompressed As GZipStream
fsSource = New FileStream("update.zip", FileMode.Open, FileAccess.Read, FileShare.Read)
gzDeCompressed = New GZipStream(fsSource, CompressionMode.Decompress, True)
'bufferwrite = new byte[4];
bufferWrite = New Byte(4) {}
fsSource.Position = fsSource.Length - 4
fsSource.Read(bufferWrite, 0, 4)
fsSource.Position = 0
Dim bufferLength As Integer = BitConverter.ToInt32(bufferWrite, 0)
Dim buffer As Byte() = New Byte(bufferLength + 100) {}
Dim readOffSet = 0
Dim totalBytes = 0
While True
Dim bytesRead = gzDeCompressed.Read(buffer, readOffSet, 100)
If bytesRead = 0 Then
'break;
readOffSet += bytesRead
totalBytes += bytesRead
End If
End While
fsDest = New FileStream(My.Application.Info.DirectoryPath & "\file.cache", FileMode.Create)
fsDest.Write(buffer, 0, totalBytes)
fsSource.Close()
gzDeCompressed.Close()
fsDest.Close()
复制代码
Exception : Magic Number
Google说是Header,可是……我使用7z Compress的
作者:
voyager
时间:
2009-9-24 02:06 PM
unzip之前要check是'gzip'还是'deflate',然后用不同的方法去decompress
直接用.net 2.0 的 system.io.compression 就可以了......
作者:
goodhermit95
时间:
2009-9-28 10:32 AM
标题:
回复 #2 voyager 的帖子
我上网找过了,他们说GZIP很多问题,而且好像只可以压缩一个文件?
然后解压只可以用Windows所压缩的文件
winrar /7zip就解压不到了
作者:
voyager
时间:
2009-9-28 05:58 PM
gzip没有问题的,很common的压缩演算法
不过很多时候,压缩法会把gzip/deflate搞混,
所以unzip前先check看吧
rar那些当然就不能用gzip咯
欢迎光临 JBTALKS.CC (https://www.jbtalks.cc/)
Powered by Discuz! X2.5