Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 2064|回复: 3
打印 上一主题 下一主题

【疑问】GZipStream Magic Number Exception

[复制链接]

62

主题

5

好友

3715

积分

本站名嘴

Rank: 11Rank: 11

跳转到指定楼层
1#
发表于 2009-7-10 11:57 PM |只看该作者 |倒序浏览

  1. Dim bufferWrite As Byte()
  2.             Dim fsSource As FileStream
  3.             Dim fsDest As FileStream
  4.             Dim gzDeCompressed As GZipStream

  5.             fsSource = New FileStream("update.zip", FileMode.Open, FileAccess.Read, FileShare.Read)
  6.             gzDeCompressed = New GZipStream(fsSource, CompressionMode.Decompress, True)
  7.             'bufferwrite = new byte[4];
  8.             bufferWrite = New Byte(4) {}

  9.             fsSource.Position = fsSource.Length - 4
  10.             fsSource.Read(bufferWrite, 0, 4)
  11.             fsSource.Position = 0
  12.             Dim bufferLength As Integer = BitConverter.ToInt32(bufferWrite, 0)
  13.             Dim buffer As Byte() = New Byte(bufferLength + 100) {}
  14.             Dim readOffSet = 0
  15.             Dim totalBytes = 0
  16.             While True
  17.                 Dim bytesRead = gzDeCompressed.Read(buffer, readOffSet, 100)
  18.                 If bytesRead = 0 Then
  19.                     'break;

  20.                     readOffSet += bytesRead
  21.                     totalBytes += bytesRead
  22.                 End If
  23.             End While
  24.             fsDest = New FileStream(My.Application.Info.DirectoryPath & "\file.cache", FileMode.Create)
  25.             fsDest.Write(buffer, 0, totalBytes)
  26.             fsSource.Close()
  27.             gzDeCompressed.Close()
  28.             fsDest.Close()
复制代码


Exception : Magic Number
Google说是Header,可是……我使用7z Compress的




收藏收藏0

4

主题

0

好友

157

积分

高级会员

Rank: 3Rank: 3Rank: 3

2#
发表于 2009-9-24 02:06 PM |只看该作者
unzip之前要check是'gzip'还是'deflate',然后用不同的方法去decompress
直接用.net 2.0 的 system.io.compression 就可以了......


回复

使用道具 举报

62

主题

5

好友

3715

积分

本站名嘴

Rank: 11Rank: 11

3#
发表于 2009-9-28 10:32 AM |只看该作者

回复 #2 voyager 的帖子

我上网找过了,他们说GZIP很多问题,而且好像只可以压缩一个文件?
然后解压只可以用Windows所压缩的文件
winrar /7zip就解压不到了


回复

使用道具 举报

4

主题

0

好友

157

积分

高级会员

Rank: 3Rank: 3Rank: 3

4#
发表于 2009-9-28 05:58 PM |只看该作者
gzip没有问题的,很common的压缩演算法
不过很多时候,压缩法会把gzip/deflate搞混,
所以unzip前先check看吧

rar那些当然就不能用gzip咯


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-7-3 08:06 AM , Processed in 0.109153 second(s), 26 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部