// Constructor public QuatCrusher(CompressLevel compressLevel, bool showEnableToggle = false, bool isStandalone = true) { this._compressLevel = compressLevel; this.bits = (int)compressLevel; this.showEnableToggle = showEnableToggle; this.isStandalone = isStandalone; }
// Constructor public QuatCrusher(bool showEnableToggle = false, bool isStandalone = true) { this.bits = 32; this._compressLevel = (QC_ISPRO) ? CompressLevel.SetBits : CompressLevel.uint32Med; this.showEnableToggle = showEnableToggle; this.isStandalone = isStandalone; }
/// <summary> /// Creates a new file as a writeable GZipStream /// </summary> /// <param name="fileName">The name of the compressed file to create</param> /// <param name="level">The compression level to use when adding data</param> /// <exception cref="ZLibException">If an error occurred in the internal zlib function</exception> public GZipStream(string fileName, CompressLevel level) { _isWriting = true; _gzFile = gzopen(fileName, String.Format("wb{0}", (int)level)); if (_gzFile == IntPtr.Zero) throw new ZLibException(-1, "Could not open " + fileName); }
/// <summary> /// Constructs an new instance of the <c>Deflater</c> /// </summary> /// <param name="level">The compression level to use for this <c>Deflater</c></param> public Deflater(CompressLevel level) : base() { int retval = deflateInit_(ref _ztream, (int)level, Info.Version, Marshal.SizeOf(_ztream)); if (retval != 0) throw new ZLibException(retval, "Could not initialize deflater"); resetOutput(); }
// Constructor public QuatCrusher(int bits, bool showEnableToggle = false, bool isStandalone = true) { this.bits = (QC_ISPRO) ? bits : RoundBitsToBestPreset(bits); this._compressLevel = CompressLevel.SetBits; this.showEnableToggle = showEnableToggle; this.isStandalone = isStandalone; }
/// <summary> /// Creates a new file as a writeable GZipStream /// </summary> /// <param name="fileName">The name of the compressed file to create</param> /// <param name="level">The compression level to use when adding data</param> /// <exception cref="ZLibException">If an error occurred in the internal zlib function</exception> public GZipStream(string fileName, CompressLevel level) { _isWriting = true; _gzFile = gzopen(fileName, String.Format("wb{0}", (int)level)); if (_gzFile == IntPtr.Zero) { throw new ZLibException(-1, "Could not open " + fileName); } }
public Deflater(CompressLevel level) { int num = deflateInit_(ref _ztream, (int)level, Info.Version, Marshal.SizeOf(_ztream)); if (num != 0) { throw new ZLibException(num, "Could not initialize deflater"); } resetOutput(); }
public static int Create(string zipFilePath, string[] files, string password = null, CompressLevel compressLevel = CompressLevel.Level1) { List <ZipFileEntry> fileEntries = new List <ZipFileEntry>(); foreach (string file in files) { fileEntries.Add(new ZipFileEntry() { FilePath = file, RelativePath = null, }); } return(Create(zipFilePath, fileEntries.ToArray(), password, compressLevel)); }
/// <summary> /// Creates the space. /// </summary> /// <param name="spaceName">Name of the space.</param> /// <param name="cLevel">The c level.</param> public static void CreateSpace(string spaceName, CompressLevel cLevel) { if (string.IsNullOrEmpty(spaceName)) { spaceName = DEFAULTSPACENAME; } if (spaces.ContainsKey(spaceName)) { spaces[spaceName] = new PdfObjectSpace(cLevel); } else { spaces.Add(spaceName, new PdfObjectSpace(cLevel)); } }
/// <summary> /// 压缩文件夹 /// </summary> /// <param name="destFile">压缩后的文件</param> /// <param name="srcFolder">压缩文件夹</param> /// <param name="password">密码</param> /// <param name="level">压缩级别</param> /// <returns></returns> public static int Zip(string destFile, string srcFolder, string password, CompressLevel level) { ZipOutputStream zipStream = null; FileStream streamWriter = null; ///文件数 int count = 0; try { //Use Crc32 //Crc32 crc32 = new Crc32(); //Create Zip File zipStream = new ZipOutputStream(File.Create(destFile)); //Specify Level zipStream.SetLevel(Convert.ToInt32(level)); //Specify Password if (password != null && password.Trim().Length > 0) { zipStream.Password = password; } count = PutDirectoryToZipStream(srcFolder, null, zipStream, /* crc32,*/ streamWriter); } catch (Exception ex) { JLog.Instance.Error(ex.Message); } finally { //Clear Resource if (streamWriter != null) { streamWriter.Close(); } if (zipStream != null) { zipStream.Finish(); zipStream.Close(); } } return(count); }
public GZipStream(string fileName, CompressLevel level, bool rsyncable = false, int bufferSize = -1) { _isWriting = true; _isRsyncable = rsyncable; _gzFile = gzopen(fileName, $"wb{(int)level}"); if (_gzFile == IntPtr.Zero) { throw new ZLibException(-1, "Could not open " + fileName); } if (bufferSize > 0) { int num = gzbuffer(_gzFile, (uint)bufferSize); if (num < 0) { throw new ZLibException(num, "Couldn't set buffer size " + bufferSize + " for filename " + fileName); } } }
/// <summary> /// Opens an existing file as a readable GZipFileStream /// </summary> /// <param name="fileName">The name of the file to open</param> /// <param name="access">The file access pattern</param> /// <param name="level">The compression level to use</param> /// <exception cref="ZLibException">If an error occurred in the internal zlib function</exception> public GZipFileStream(string fileName, FileAccess access, CompressLevel level) { switch (access) { case FileAccess.Read: _isWriting = false; _gzFile = ZLibNative.gzopen(fileName, "rb"); break; case FileAccess.Write: _isWriting = true; _gzFile = ZLibNative.gzopen(fileName, String.Format("wb{0}", (int)level)); break; case FileAccess.ReadWrite: throw new ArgumentException(String.Format("{0} cannot be used with {1}", access, GetType().FullName), "access"); } if (_gzFile == IntPtr.Zero) throw new ZLibException(-1, "Could not open " + fileName); }
/// <summary> /// Opens an existing file as a readable GZipFileStream /// </summary> /// <param name="fileName">The name of the file to open</param> /// <param name="access">The file access pattern</param> /// <param name="level">The compression level to use</param> /// <exception cref="ZLibException">If an error occurred in the internal zlib function</exception> public GZipFileStream(string fileName, FileAccess access, CompressLevel level) { switch (access) { case FileAccess.Read: _isWriting = false; _gzFile = ZLibNative.gzopen(fileName, "rb"); break; case FileAccess.Write: _isWriting = true; _gzFile = ZLibNative.gzopen(fileName, String.Format("wb{0}", (int)level)); break; case FileAccess.ReadWrite: throw new ArgumentException(String.Format("{0} cannot be used with {1}", access, GetType().FullName), "access"); } if (_gzFile == IntPtr.Zero) { throw new ZLibException(-1, "Could not open " + fileName); } }
/// <summary> /// Initializes a new instance of the <see cref="T:Dt.Pdf.BaseObject.PdfObjectSpace" /> class. /// </summary> /// <param name="cLevel">The c level.</param> public PdfObjectSpace(CompressLevel cLevel) { this.level = cLevel; }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(r, label, property); base.OnGUI(r, property, label); property.serializedObject.Update(); target = (QuatCrusher)DrawerUtils.GetParent(property.FindPropertyRelative("bits")); MonoBehaviour component = (MonoBehaviour)property.serializedObject.targetObject; if (target.transform == null) { target.transform = component.transform; } line = r.yMin; float standalonesheight = target.isStandalone ? (SPACING + LINEHEIGHT) * 2 : 0; float boxheight = SPACING + HHEIGHT + SPACING + LINEHEIGHT + standalonesheight + SPACING; SolidTextures.DrawTexture(new Rect(r.xMin - 1, line - 1, r.width + 2, boxheight + 2), SolidTextures.lowcontrast2D); SolidTextures.DrawTexture(new Rect(r.xMin, line, r.width, boxheight), SolidTextures.gray2D); line += SPACING; DrawHeader(new Rect(r)); line += HHEIGHT + SPACING; CompressLevel clvl = (CompressLevel)EditorGUI.EnumPopup(new Rect(paddedleft, line, labelwidth - PADDING, LINEHEIGHT), GUIContent.none, target.CompressLevel); if (!QC_ISPRO) { // In case we went from pro to free... quietly set this back to non-custom. if (target.CompressLevel == CompressLevel.SetBits) { target.Bits = (int)target.CompressLevel; // CompressLevel = CompressLevel.uint32Med; } else if (clvl == CompressLevel.SetBits) { ProFeatureDialog(""); target.CompressLevel = (CompressLevel)target.Bits; } else { target.CompressLevel = clvl; } } else if (clvl != target.CompressLevel) { target.CompressLevel = clvl; } var bitssp = property.FindPropertyRelative("bits"); GUI.enabled = (QC_ISPRO); EditorGUI.PropertyField(new Rect(fieldleft, line, fieldwidth, LINEHEIGHT), bitssp, GUIContent.none); GUI.enabled = true; if (QC_ISPRO && bitssp.intValue != target.Bits) { target.CompressLevel = CompressLevel.SetBits; } if (target.isStandalone) { line += LINEHEIGHT + SPACING; EditorGUI.PropertyField(new Rect(paddedleft, line, paddedwidth, LINEHEIGHT), property.FindPropertyRelative("transform")); line += LINEHEIGHT + SPACING; EditorGUI.PropertyField(new Rect(paddedleft, line, paddedwidth, LINEHEIGHT), property.FindPropertyRelative("local")); } property.serializedObject.ApplyModifiedProperties(); EditorGUI.EndProperty(); }
public static int Zip(string destFolder, string[] srcFiles, string folderName, string password, CompressLevel level) { ZipOutputStream zipStream = null; FileStream streamWriter = null; int count = 0; try { //Use Crc32 Crc32 crc32 = new Crc32(); //Create Zip File zipStream = new ZipOutputStream(File.Create(destFolder)); //Specify Level zipStream.SetLevel(Convert.ToInt32(level)); //Specify Password if (password != null && password.Trim().Length > 0) { zipStream.Password = password; } //Foreach File foreach (string file in srcFiles) { //Check Whether the file exists if (!File.Exists(file)) { throw new FileNotFoundException(file); } //Read the file to stream streamWriter = File.OpenRead(file); byte[] buffer = new byte[streamWriter.Length]; streamWriter.Read(buffer, 0, buffer.Length); streamWriter.Close(); //Specify ZipEntry crc32.Reset(); crc32.Update(buffer); ZipEntry zipEntry = new ZipEntry(Path.Combine(folderName, Path.GetFileName(file))); zipEntry.DateTime = DateTime.Now; zipEntry.Size = buffer.Length; zipEntry.Crc = crc32.Value; //Put file info into zip stream zipStream.PutNextEntry(zipEntry); //Put file data into zip stream zipStream.Write(buffer, 0, buffer.Length); count++; } } catch { throw; } finally { //Clear Resource if (streamWriter != null) { streamWriter.Close(); } if (zipStream != null) { zipStream.Finish(); zipStream.Close(); } } return(count); }
// Constructor public QuatCrusher() { this._compressLevel = CompressLevel.uint64Hi; this.showEnableToggle = false; this.isStandalone = true; }
public ZipArchivator() { compressLevel = CompressLevel.Optimal; }
/// <summary> /// Compress a stream with ZLib /// </summary> /// <param name="snipStreamWrapper">A stream wrapper object</param> /// <param name="compressLevel">Compression level of stream.</param> public static void Compress(SnipStreamWrapper snipStreamWrapper, CompressLevel compressLevel) { var numBytesAddressing = snipStreamWrapper.OutputBufferLength; ZLibWrapper.CopyByteArrayToInputBuffer(snipStreamWrapper.OutputBuffer, 0, snipStreamWrapper.OutputBufferLength); if (_deflaterBest == null) { _deflaterBest = new Deflater(CompressLevel.Best); _deflaterBest.DataAvailable += ZLibWrapper.WriteInOutputBuffer; } if (_deflaterNone == null) { _deflaterNone = new Deflater(CompressLevel.None); _deflaterNone.DataAvailable += ZLibWrapper.WriteInOutputBuffer; } if (_deflaterFastest == null) { _deflaterFastest = new Deflater(CompressLevel.Fastest); _deflaterFastest.DataAvailable += ZLibWrapper.WriteInOutputBuffer; } if (_deflaterDefault == null) { _deflaterDefault = new Deflater(CompressLevel.Default); _deflaterDefault.DataAvailable += ZLibWrapper.WriteInOutputBuffer; } try { while (numBytesAddressing > 0u) { uint numBytes = Math.Min(numBytesAddressing, 8192u); //8192u); 65536u if (compressLevel == CompressLevel.None) _deflaterNone.Add(ZLibWrapper.ReadBytes((int) numBytes, ZLibBufferType.InputBuffer)); if (compressLevel == CompressLevel.Best) _deflaterBest.Add(ZLibWrapper.ReadBytes((int) numBytes, ZLibBufferType.InputBuffer)); if (compressLevel == CompressLevel.Default) _deflaterDefault.Add(ZLibWrapper.ReadBytes((int) numBytes, ZLibBufferType.InputBuffer)); if (compressLevel == CompressLevel.Fastest) _deflaterFastest.Add(ZLibWrapper.ReadBytes((int) numBytes, ZLibBufferType.InputBuffer)); numBytesAddressing -= numBytes; } string deflateErrorMsg = string.Empty; if (compressLevel == CompressLevel.None) deflateErrorMsg = _deflaterNone._ztream.msg; if (compressLevel == CompressLevel.Best) deflateErrorMsg = _deflaterBest._ztream.msg; if (compressLevel == CompressLevel.Default) deflateErrorMsg = _deflaterDefault._ztream.msg; if (compressLevel == CompressLevel.Fastest) deflateErrorMsg = _deflaterFastest._ztream.msg; if (!string.IsNullOrWhiteSpace(deflateErrorMsg)) MessageBox.Show(string.Format("ZLib.Compress: {0}", deflateErrorMsg), TranslateUI.TranslateUiGlobalization.ResManager.GetString("ZLib_Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); if (compressLevel == CompressLevel.None) _deflaterNone.Finish(); // flush zlib buffer if (compressLevel == CompressLevel.Best) _deflaterBest.Finish(); // flush zlib buffer if (compressLevel == CompressLevel.Default) _deflaterDefault.Finish(); // flush zlib buffer if (compressLevel == CompressLevel.Fastest) _deflaterFastest.Finish(); // flush zlib buffer ZLibWrapper.Position(0, ZLibBufferType.OutputBuffer); } catch (Exception ex) { MessageBox.Show( string.Format(TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "MSG_ErrorWithNewLine"), arg0: ex), TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "ZLib_Compress"), MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (ZLibWrapper.OutputBufferLength == 0) { MessageBox.Show( TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "ZLib_OutputBufferEmpty"), TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "ZLib_Compress"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Compress a stream with ZLib /// </summary> /// <param name="snipStreamWrapper">A stream wrapper object</param> /// <param name="compressLevel">Compression level of stream.</param> public static void Compress(SnipStreamWrapper snipStreamWrapper, CompressLevel compressLevel) { var numBytesAddressing = snipStreamWrapper.OutputBufferLength; ZLibWrapper.CopyByteArrayToInputBuffer(snipStreamWrapper.OutputBuffer, 0, snipStreamWrapper.OutputBufferLength); if (_deflaterBest == null) { _deflaterBest = new Deflater(CompressLevel.Best); _deflaterBest.DataAvailable += ZLibWrapper.WriteInOutputBuffer; } if (_deflaterNone == null) { _deflaterNone = new Deflater(CompressLevel.None); _deflaterNone.DataAvailable += ZLibWrapper.WriteInOutputBuffer; } if (_deflaterFastest == null) { _deflaterFastest = new Deflater(CompressLevel.Fastest); _deflaterFastest.DataAvailable += ZLibWrapper.WriteInOutputBuffer; } if (_deflaterDefault == null) { _deflaterDefault = new Deflater(CompressLevel.Default); _deflaterDefault.DataAvailable += ZLibWrapper.WriteInOutputBuffer; } try { while (numBytesAddressing > 0u) { uint numBytes = Math.Min(numBytesAddressing, 8192u); //8192u); 65536u if (compressLevel == CompressLevel.None) { _deflaterNone.Add(ZLibWrapper.ReadBytes((int)numBytes, ZLibBufferType.InputBuffer)); } if (compressLevel == CompressLevel.Best) { _deflaterBest.Add(ZLibWrapper.ReadBytes((int)numBytes, ZLibBufferType.InputBuffer)); } if (compressLevel == CompressLevel.Default) { _deflaterDefault.Add(ZLibWrapper.ReadBytes((int)numBytes, ZLibBufferType.InputBuffer)); } if (compressLevel == CompressLevel.Fastest) { _deflaterFastest.Add(ZLibWrapper.ReadBytes((int)numBytes, ZLibBufferType.InputBuffer)); } numBytesAddressing -= numBytes; } string deflateErrorMsg = string.Empty; if (compressLevel == CompressLevel.None) { deflateErrorMsg = _deflaterNone._ztream.msg; } if (compressLevel == CompressLevel.Best) { deflateErrorMsg = _deflaterBest._ztream.msg; } if (compressLevel == CompressLevel.Default) { deflateErrorMsg = _deflaterDefault._ztream.msg; } if (compressLevel == CompressLevel.Fastest) { deflateErrorMsg = _deflaterFastest._ztream.msg; } if (!string.IsNullOrWhiteSpace(deflateErrorMsg)) { MessageBox.Show(string.Format("ZLib.Compress: {0}", deflateErrorMsg), TranslateUI.TranslateUiGlobalization.ResManager.GetString("ZLib_Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } if (compressLevel == CompressLevel.None) { _deflaterNone.Finish(); // flush zlib buffer } if (compressLevel == CompressLevel.Best) { _deflaterBest.Finish(); // flush zlib buffer } if (compressLevel == CompressLevel.Default) { _deflaterDefault.Finish(); // flush zlib buffer } if (compressLevel == CompressLevel.Fastest) { _deflaterFastest.Finish(); // flush zlib buffer } ZLibWrapper.Position(0, ZLibBufferType.OutputBuffer); } catch (Exception ex) { MessageBox.Show( string.Format(TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "MSG_ErrorWithNewLine"), arg0: ex), TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "ZLib_Compress"), MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (ZLibWrapper.OutputBufferLength == 0) { MessageBox.Show( TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "ZLib_OutputBufferEmpty"), TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "ZLib_Compress"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// 按指定的压缩等级,加密类型及秘钥压缩写入指定流 /// </summary> /// <param name="stream">要压缩写入的流</param> /// <param name="compressLevel">压缩等级</param> /// <param name="encryptType">加密类型</param> /// <param name="key">加密秘钥</param> public void Write(Stream stream, CompressLevel compressLevel = CompressLevel.Normal, EncryptType encryptType = EncryptType.None, byte[] key = null) { Write(stream, (byte)compressLevel, (byte)encryptType, key); }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(r, label, property); haschanged = false; base.OnGUI(r, property, label); holdindent = EditorGUI.indentLevel; property.serializedObject.ApplyModifiedProperties(); property.serializedObject.Update(); target = (QuatCrusher)DrawerUtils.GetParent(property.FindPropertyRelative("bits")); line = r.yMin; //float standalonesheight = target.isStandalone ? (SPACING + LINEHEIGHT) * 2 : 0; //float boxheight = SPACING + HEADR_HGHT + SPACING + LINEHEIGHT + standalonesheight + SPACING; SolidTextures.DrawTexture(ir, SolidTextures.gray2D); //SolidTextures.DrawTexture(new Rect(ir.xMin - 1, line - 1, r.width + 2, boxheight + 2), SolidTextures.lowcontrast2D); //SolidTextures.DrawTexture(new Rect(ir.xMin, line, r.width, boxheight), SolidTextures.gray2D); line += SPACING; DrawHeader(new Rect(r)); line += HEADR_HGHT + SPACING + SPACING; EditorGUI.indentLevel = 0; CompressLevel clvl = (CompressLevel)EditorGUI.EnumPopup(new Rect(ir.xMin + PADDING, line, labelwidth - PADDING, LINEHEIGHT), GUIContent.none, target.CompressLevel); EditorGUI.indentLevel = holdindent; if (!QC_ISPRO) { // In case we went from pro to free... quietly set this back to non-custom. if (target.CompressLevel == CompressLevel.SetBits) { if (target.Bits != (int)target.CompressLevel) { haschanged = true; target.Enabled = true; target.Bits = (int)target.CompressLevel; // CompressLevel = CompressLevel.uint32Med; } } else if (clvl == CompressLevel.SetBits) { ProFeatureDialog(""); if (target.CompressLevel != (CompressLevel)target.Bits) { haschanged = true; target.CompressLevel = (CompressLevel)target.Bits; } } else { if (target.CompressLevel != clvl) { target.Enabled = true; haschanged = true; target.CompressLevel = clvl; } } } else if (clvl != target.CompressLevel) { haschanged = true; target.CompressLevel = clvl; } //var bitssp = property.FindPropertyRelative("bits"); GUI.enabled = (QC_ISPRO); int newbits = EditorGUI.IntSlider(new Rect(fieldleft, line, fieldwidth, LINEHEIGHT), GUIContent.none, target.Bits, 16, 64); //bool bitschanged = EditorGUI.PropertyField(new Rect(fieldleft, line, fieldwidth, LINEHEIGHT), bitssp, GUIContent.none); GUI.enabled = true; if (QC_ISPRO && newbits != target.Bits) { //if (target.CompressLevel != CompressLevel.SetBits) //{ haschanged = true; target.Bits = newbits; //target.CompressLevel = CompressLevel.SetBits; //} property.serializedObject.Update(); } if (target.isStandalone) { line += LINEHEIGHT + SPACING; EditorGUI.PropertyField(new Rect(paddedleft, line, paddedwidth, LINEHEIGHT), property.FindPropertyRelative("transform")); line += LINEHEIGHT + SPACING; EditorGUI.PropertyField(new Rect(paddedleft, line, paddedwidth, LINEHEIGHT), property.FindPropertyRelative("local")); } property.serializedObject.ApplyModifiedProperties(); if (haschanged) { EditorUtility.SetDirty(property.serializedObject.targetObject); //AssetDatabase.SaveAssets(); } EditorGUI.EndProperty(); }
public void CopyFrom(QuatCrusher source) { bits = source.bits; _compressLevel = source._compressLevel; local = source.local; }
public static int Create(string zipFilePath, ZipFileEntry[] files, string password = null, CompressLevel compressLevel = CompressLevel.Level1) { ZipOutputStream zipOutputStream = null; FileStream fileStream = null; int count = 0; try { if (File.Exists(zipFilePath)) { File.Delete(zipFilePath); } Directory.CreateDirectory(Path.GetDirectoryName(zipFilePath)); Crc32 crc32 = new Crc32(); zipOutputStream = new ZipOutputStream(File.Create(zipFilePath)); zipOutputStream.SetLevel(Convert.ToInt32(compressLevel)); if (password != null && password.Trim().Length > 0) { zipOutputStream.Password = password; } foreach (ZipFileEntry file in files) { if (!string.IsNullOrEmpty(file.FilePath) && File.Exists(file.FilePath)) { byte[] buffer = new byte[] { }; using (FileStream stream = File.OpenRead(file.FilePath)) { if (stream.Length > 0) { buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); } stream.Close(); } crc32.Reset(); crc32.Update(buffer); ZipEntry zipEntry = new ZipEntry(Path.Combine( file.RelativePath ?? string.Empty, Path.GetFileName(file.FilePath))); zipEntry.Flags |= (int)GeneralBitFlags.UnicodeText; zipEntry.DateTime = DateTime.Now; zipEntry.Size = buffer.Length; zipEntry.Crc = crc32.Value; zipOutputStream.PutNextEntry(zipEntry); zipOutputStream.Write(buffer, 0, buffer.Length); count++; } } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } finally { if (fileStream != null) { fileStream.Close(); } if (zipOutputStream != null) { zipOutputStream.Finish(); zipOutputStream.Close(); } } return(count); }
/// <summary> /// 按指定的压缩等级,加密类型及压缩秘钥写入文件流字典 /// </summary> /// <param name="fileStreams">文件流字典,其键值指示了文件的相对路径</param> /// <param name="compressLevel">压缩等级</param> /// <param name="encryptType">加密类型</param> /// <param name="key">加密秘钥</param> public void Write(Dictionary <string, FileStream> fileStreams, CompressLevel compressLevel = CompressLevel.Normal, EncryptType encryptType = EncryptType.None, byte[] key = null) { Write(fileStreams, (byte)compressLevel, (byte)encryptType, key); }
/// <summary> /// Decompress a stream with ZLib /// </summary> /// <param name="compressLevel">Compression level of stream</param> /// <param name="expectedSize">Expected size</param> public static void Decompress(out CompressLevel compressLevel, int expectedSize = 0) { uint numBytesAddressing = ZLibWrapper.InputBufferLength; compressLevel = CompressLevel.None; try { ZLibWrapper.Position(0, ZLibBufferType.InputBuffer); compressLevel = RetrieveCompressionLevel(); ZLibWrapper.Position(0, ZLibBufferType.InputBuffer); if (expectedSize == 0) { // no decompression. copy input buffer in output buffer ZLibWrapper.CopyInputBufferToOutputBuffer(8); compressLevel = CompressLevel.None; // for compression } else { if (_inflater == null) { _inflater = new Inflater(); _inflater.DataAvailable += ZLibWrapper.WriteInOutputBuffer; } while (numBytesAddressing > 0u) { uint numBytes = Math.Min(numBytesAddressing, 8192u); //8192u); 65536u _inflater.Add(ZLibWrapper.ReadBytes((int) numBytes, ZLibBufferType.InputBuffer)); numBytesAddressing -= numBytes; } string inflateErrorMsg = _inflater._ztream.msg; if (!string.IsNullOrWhiteSpace(inflateErrorMsg)) MessageBox.Show(string.Format("ZLib.Decompress: {0}", inflateErrorMsg), TranslateUI.TranslateUiGlobalization.ResManager.GetString("ZLib_Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); _inflater.Finish(); //flush zlib buffer } ZLibWrapper.Position(0, ZLibBufferType.OutputBuffer); } catch (Exception ex) { MessageBox.Show( string.Format(TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "MSG_ErrorWithNewLine"), ex), TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "ZLib_Decompress"), MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (ZLibWrapper.OutputBufferLength == 0) { MessageBox.Show( TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "ZLib_OutputBufferEmpty"), TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "ZLib_Decompress"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Decompress a stream with ZLib /// </summary> /// <param name="compressLevel">Compression level of stream</param> /// <param name="expectedSize">Expected size</param> public static void Decompress(out CompressLevel compressLevel, int expectedSize = 0) { uint numBytesAddressing = ZLibWrapper.InputBufferLength; compressLevel = CompressLevel.None; try { ZLibWrapper.Position(0, ZLibBufferType.InputBuffer); compressLevel = RetrieveCompressionLevel(); ZLibWrapper.Position(0, ZLibBufferType.InputBuffer); if (expectedSize == 0) { // no decompression. copy input buffer in output buffer ZLibWrapper.CopyInputBufferToOutputBuffer(8); compressLevel = CompressLevel.None; // for compression } else { if (_inflater == null) { _inflater = new Inflater(); _inflater.DataAvailable += ZLibWrapper.WriteInOutputBuffer; } while (numBytesAddressing > 0u) { uint numBytes = Math.Min(numBytesAddressing, 8192u); //8192u); 65536u _inflater.Add(ZLibWrapper.ReadBytes((int)numBytes, ZLibBufferType.InputBuffer)); numBytesAddressing -= numBytes; } string inflateErrorMsg = _inflater._ztream.msg; if (!string.IsNullOrWhiteSpace(inflateErrorMsg)) { MessageBox.Show(string.Format("ZLib.Decompress: {0}", inflateErrorMsg), TranslateUI.TranslateUiGlobalization.ResManager.GetString("ZLib_Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } _inflater.Finish(); //flush zlib buffer } ZLibWrapper.Position(0, ZLibBufferType.OutputBuffer); } catch (Exception ex) { MessageBox.Show( string.Format(TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "MSG_ErrorWithNewLine"), ex), TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "ZLib_Decompress"), MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (ZLibWrapper.OutputBufferLength == 0) { MessageBox.Show( TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "ZLib_OutputBufferEmpty"), TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "ZLib_Decompress"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } }