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#代码
* 解压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#代码
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;
}
}