/// <summary> /// Decompress the byte array previously returned by /// compress /// </summary> public static byte[] Decompress(sbyte[] value, int offset, int length) { // Create an expandable byte array to hold the decompressed data ByteArrayOutputStream bos = new ByteArrayOutputStream(length); Inflater decompressor = SharpZipLib.CreateInflater(); try { decompressor.SetInput((byte[])(Array)value); // Decompress the data byte[] buf = new byte[1024]; while (!decompressor.IsFinished) { int count = decompressor.Inflate(buf); bos.Write(buf, 0, count); } } finally { } return(bos.ToArray()); }
/// <summary> /// Compresses the specified byte range using the /// specified compressionLevel (constants are defined in /// java.util.zip.Deflater). /// </summary> public static byte[] Compress(sbyte[] value, int offset, int length, int compressionLevel) { /* Create an expandable byte array to hold the compressed data. * You cannot use an array that's the same size as the orginal because * there is no guarantee that the compressed data will be smaller than * the uncompressed data. */ ByteArrayOutputStream bos = new ByteArrayOutputStream(length); Deflater compressor = SharpZipLib.CreateDeflater(); try { compressor.SetLevel(compressionLevel); compressor.SetInput((byte[])(Array)value, offset, length); compressor.Finish(); // Compress the data var buf = new byte[1024]; while (!compressor.IsFinished) { int count = compressor.Deflate(buf); bos.Write(buf, 0, count); } } finally { } return(bos.ToArray()); }
/// <summary>Decompress the byte array previously returned by /// compress /// </summary> public static byte[] Decompress(byte[] value_Renamed) { // Create an expandable byte array to hold the decompressed data System.IO.MemoryStream bos = new System.IO.MemoryStream(value_Renamed.Length); Inflater decompressor = SharpZipLib.CreateInflater(); try { decompressor.SetInput(value_Renamed); // Decompress the data byte[] buf = new byte[1024]; while (!decompressor.IsFinished) { int count = decompressor.Inflate(buf); bos.Write(buf, 0, count); } } finally { } return(bos.ToArray()); }
/// <summary> /// 下载文件方法 /// </summary> /// <param name="data">二进制流</param> /// <param name="fileName">文件名</param> /// <param name="fileType">后缀后</param> protected virtual void OutputStream(byte[] data, string fileName, string fileType) { byte[] attachment = SharpZipLib.DeCompress(data); FineOffice.Web.FileTypeHelper typeHelper = new FineOffice.Web.FileTypeHelper(); Response.Clear(); Response.Buffer = true; Response.Charset = "utf-8"; Response.AddHeader("Content-Disposition", "attachment; filename=" + typeHelper.ToHexString(fileName + "." + fileType)); Response.AddHeader("Content-Length", attachment.Length.ToString()); Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); Response.OutputStream.Write(attachment, 0, attachment.Length); Response.Flush(); }
protected void btnDownAttachment_Click(object sender, EventArgs e) { int id = int.Parse(attachmentGrid.DataKeys[attachmentGrid.SelectedRowIndex][0].ToString()); FineOffice.Modules.OA_Attachment model = attBll.GetModel(d => d.ID == id); byte[] attachmentData = SharpZipLib.DeCompress(model.AttachmentData); FineOffice.Web.FileTypeHelper typeHelper = new FineOffice.Web.FileTypeHelper(); Response.Clear(); Response.Buffer = true; Response.Charset = "utf-8"; Response.AddHeader("Content-Disposition", "attachment; filename=" + typeHelper.ToHexString(model.FileName + "." + model.XType)); Response.AddHeader("Content-Length", attachmentData.Length.ToString()); Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); Response.OutputStream.Write(attachmentData, 0, attachmentData.Length); Response.Flush(); }
protected void btnDownForm_Click(object sender, EventArgs e) { int id = int.Parse(formGrid.DataKeys[formGrid.SelectedRowIndex][0].ToString()); FineOffice.Modules.OA_FlowRunData model = runDataBll.GetModel(d => d.ID == id); byte[] formData = SharpZipLib.DeCompress(model.FormData); this.Response.Clear(); this.Response.Buffer = true; this.Response.Charset = "utf-8"; this.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(model.Title + "." + model.XType)); this.Response.AddHeader("Content-Length", formData.Length.ToString()); this.Response.ContentType = "application/msword"; this.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); this.Response.OutputStream.Write(formData, 0, formData.Length); this.Response.Flush(); }
internal DeflateCompressor(int level) { Compressor = SharpZipLib.CreateDeflater(); Compressed = new byte[64]; }
internal DeflateDecompressor() { decompressor = SharpZipLib.CreateInflater(); Compressed = new byte[0]; }