为了账号安全,请及时绑定邮箱和手机立即绑定

如何在C#中获取解压缩的gzipstream的位置和长度?

如何在C#中获取解压缩的gzipstream的位置和长度?

C#
HUX布斯 2021-03-30 13:18:24
我正在尝试使用二进制阅读器读取.gz文件,方法是首先使用gzipstream解压缩,然后使用gzipstream创建一个新的二进制阅读器。但是,当我尝试使用BinaryReader的BaseStream.Position和BaseStream.Length(以了解我何时位于文件末尾)时,我收到了NotSupportedException,请检查GZipStream类中这些字段的doc显示:Length不支持此属性,并且始终抛出NotSupportedException。(重写Stream.Length。)Position不支持此属性,并且始终抛出NotSupportedException。(重写Stream.Position。)所以我的问题是,当我使用BinaryReader读取解压缩的GZipStream时,如何知道文件的末尾位置?谢谢这是我的代码:Stream stream = new MemoryStream(textAsset.bytes);GZipStream zippedStream = new GZipStream(stream, CompressionMode.Decompress);using (BinaryReader reader = new BinaryReader(zippedStream))    while(reader.BaseStream.Position != reader.BaseStream.Length)    {        //do stuff with BinaryReader    }以上抛出:NotSupportedException:不支持该操作。System.IO.Compression.DeflateStream.get_Position()由于while()中的BaseStream.Position调用
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 264 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信