Java ZipInputStream转成C#对应的代码怎么转?

yonghua_IT 2019-04-26 04:27:53
java:

/**
* 解压byte数组类型的Zip
*
* @param data
* @return
* @throws IOException
*/
private static byte[] unZip(byte[] data) throws IOException {
byte[] b = null;
ByteArrayInputStream bis = new ByteArrayInputStream(data);
ZipInputStream zip = new ZipInputStream(bis);
while (zip.getNextEntry() != null) {
byte[] buf = new byte[8096];
int num = -1;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((num = zip.read(buf, 0, buf.length)) != -1) {
baos.write(buf, 0, num);
}
b = baos.toByteArray();
baos.flush();
baos.close();
}
zip.close();
bis.close();
return b;
}

请大神帮忙转成C#代码
...全文
123 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
bloodish 2019-04-26
  • 打赏
  • 举报
回复
GZipStream了解一下

private static byte[] UnZip(byte[] data)
        {
            try
            {
                using (var bis = new MemoryStream(data))
                using (var zip = new GZipStream(bis, CompressionMode.Decompress))
                using (var baos = new MemoryStream())
                {
                    var buf = new byte[8096];
                    var num = -1;
                    while((num = zip.Read(buf,0,buf.Length)) > 0)
                        baos.Write(buf, 0, num);
                    baos.Flush();
                    return baos.ToArray();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
  • 打赏
  • 举报
回复
zip压缩解压是统一标准,直接用对应类库就行,没必要纠结与某行具体的代码
wanghui0380 2019-04-26
  • 打赏
  • 举报
回复
自己百度“SharpZipLib”

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧