还是求助中.百度了google了找不到答案.求大神帮助中.

解决方案 »

  1.   

    我也碰到这个问题了其实很简单你先判断rsp.ContentEncoding的值是不是为空。。是的话就用stream 否则用Gzipstream
      

  2.   

      using (FileStream sourceStream = new FileStream(sourceFile, FileMode.Open))
            {
                byte[] quartetBuffer = new byte[4];//创建byte数组
                int position = (int)sourceStream.Length - 4;//获取字节流长度
                sourceStream.Position = position;//设置流当前位置
                sourceStream.Read(quartetBuffer, 0, 4);//读取字节块并写入到缓冲区
                sourceStream.Position = 0;//设置流当前位置
                int checkLength = BitConverter.ToInt32(quartetBuffer, 0);
                byte[] buffer = new byte[checkLength + 100];//创建byte数组
                //创建GZipStream对象,在执行完{}中的代码后自动释放该对象的资源
                using (GZipStream decompressedStream = new GZipStream(sourceStream, CompressionMode.Decompress, true))
                {               
                    int total = 0;
                    for (int offset = 0; ; )//循环读取字节
                    {
                        int bytesRead = decompressedStream.Read(buffer, offset, 100);   //幻数在这里不正确
                        if (bytesRead == 0) break;
                        offset += bytesRead;
                        total += bytesRead;
                    }
                    //创建FileStream对象,在执行完{}中的代码后自动释放该对象的资源
                    using (FileStream destinationStream = new FileStream(destinationFile, FileMode.Create))
                    {
                        destinationStream.Write(buffer, 0, total);//将缓冲区中的数据写入流
                        destinationStream.Flush();//清除缓冲区
                    }
                }
    不知如何修改,还请大神指教