C 檔案流壓縮解壓

2021-09-23 20:06:44 字數 2391 閱讀 5318

/// /// 檔案流壓縮解壓

///

public class ziphelper

/// /// deflate方式壓縮

///

///

/// 壓縮品質級別(0~9)

///

public static stream deflate(stream stream, int level)

/// /// deflate方式壓縮

///

///

/// 壓縮品質級別(0~9)

///

public static byte deflate(byte input, int level)

else

}catch (exception innerexception)

return result;

}#endregion

#region inflate解壓

/// /// inflate解壓

///

///

///

public static byte inflate(byte input)

else

byte buffer = memorystream.getbuffer();

memorystream.close();

result = buffer;}}

}catch (exception innerexception)

return result;

}/// /// inflate解壓

///

///

///

public static stream inflate(stream zipstream)

#endregion

#endregion

#region gzip壓縮

/// /// gzip壓縮

///

///

///

public static void gzipcompress(stream srcstream, stream output)

/// /// gzip壓縮

///

///

/// 壓縮品質級別(0~9)

///

public static void gzipcompress(stream srcstream, int compresslevel, stream output)

不在有效的範圍(1-9)內", compresslevel));

}srcstream.position = 0l;

gzipoutputstream gzipoutputstream = new gzipoutputstream(output);

gzipoutputstream.setlevel(compresslevel);

try}

catch (exception ex)

srcstream.close();

gzipoutputstream.finish();

}/// /// gzip解壓

///

///

///

public static void gzipdecompress(stream zipstream, stream outputstream)

}catch (exception ex)

zipstream.close();

gzipinputstream.close();

}#endregion

#region bzip2壓縮

/// /// bzip2壓縮

///

///

///

///

public static void bzip2compress(stream instream, stream outstream, int blocksize)

/// /// bzip2解壓

///

///

///

public static void bzip2decompress(stream instream, stream outstream)

#endregion

private static byte streamtobytes(stream stream)

private static stream bytestostream(byte bytes)

private static void streamtofile(stream stream, string filename)

private static stream filetostream(string filename)

}

C 檔案流壓縮解壓

檔案流壓縮解壓 public class ziphelper deflate方式壓縮 壓縮品質級別 0 9 public static stream deflate stream stream,int level deflate方式壓縮 壓縮品質級別 0 9 public static byte d...

壓縮 解壓縮流GZipStream

如果要在壓縮過程中檢查錯誤或要與其他作業系統所用程式共享壓縮資料,則要是用gzipstream類。gzipstream類包含是用gzip資料格式進行壓縮和解壓縮檔案的方法,該類不能用於解壓縮大於4gb的檔案。一 屬性 basestream 獲取對基礎流的引用。canread 獲取乙個值,該值指示流是...

C 壓縮解壓Zip檔案

新增引用icsharpcode.sharpziplib.dll region 加壓方法 被壓縮的資料夾夾路徑 生成壓縮檔案的路徑,為空則預設與被壓縮資料夾同一級目錄,名稱為 資料夾名 zip 出錯資訊 是否壓縮成功 public static bool zipfile string dirpath,...