/** * Generate an object that contains an CMS Compressed Data */ public CmsCompressedData Generate( CmsProcessable content, string compressionOid) { AlgorithmIdentifier comAlgId; Asn1OctetString comOcts; try { MemoryStream bOut = new MemoryStream(); ZOutputStream zOut = new ZOutputStream(bOut, JZlib.Z_DEFAULT_COMPRESSION); content.Write(zOut); zOut.Dispose(); comAlgId = new AlgorithmIdentifier(new DerObjectIdentifier(compressionOid)); comOcts = new BerOctetString(bOut.ToArray()); } catch (IOException e) { throw new CmsException("exception encoding data.", e); } ContentInfo comContent = new ContentInfo(CmsObjectIdentifiers.Data, comOcts); ContentInfo contentInfo = new ContentInfo( CmsObjectIdentifiers.CompressedData, new CompressedData(comAlgId, comContent)); return(new CmsCompressedData(contentInfo)); }
/// <summary> /// Old Decompress method not using .NET compressor /// </summary> /// <param name="Data"></param> /// <returns></returns> public byte[] DecompressOld(byte[] Data) { byte[] decompressedPixelData = new byte[UncompressedLength]; // ZLIB if (version > BgfFile.VERSION9) { // init streams MemoryStream destStream = new MemoryStream(decompressedPixelData, true); ZOutputStream destZ = new ZOutputStream(destStream); // decompress destZ.Write(Data, 0, Data.Length); destZ.Flush(); destZ.finish(); // cleanup destStream.Dispose(); destZ.Dispose(); } // CRUSH else { #if WINCLR && X86 // decompress Crush32.Decompress(Data, 0, decompressedPixelData, 0, (int)UncompressedLength, CompressedLength); #else throw new Exception(ERRORCRUSHPLATFORM); #endif } // set decompressed array to pixeldata return(decompressedPixelData); }
public static byte[] Compress(bool isCompress, byte[] input, int idxBg, int length) { byte[] ret = null; try { if (isCompress)//压缩 { using (MemoryStream memoryStream = new MemoryStream()) { ZOutputStream zos = new ZOutputStream(memoryStream, zlibConst.Z_DEFAULT_COMPRESSION); zos.Write(input, idxBg, length); zos.Dispose(); ret = memoryStream.ToArray(); memoryStream.Flush(); } } else { using (MemoryStream memoryStream = new MemoryStream()) { ZOutputStream zos = new ZOutputStream(memoryStream); //解压缩时间,调用Write_NoException,防止攻击 if (!zos.Write_NoException(input, idxBg, length)) { zos.Dispose(); return(null); } zos.Dispose(); ret = memoryStream.ToArray(); memoryStream.Flush(); } } } catch (Exception) { //LogEngine.Write(LOGTYPE.ERROR, ex.ToString()); ret = null; } return(ret); }
public void Dispose() { if (_ZOutStream != null) { _ZOutStream.Dispose(); } if (fos != null) { fos.Dispose(); } }
protected override void Dispose(bool disposing) { _out.Dispose(); // TODO Parent context(s) should really be be closed explicitly _eiGen.Close(); _cGen.Close(); _sGen.Close(); base.Dispose(disposing); }
/// <summary> /// Returns a compressed byte[] of PixelData argument /// </summary> /// <param name="Data"></param> /// <returns></returns> public byte[] Compress(byte[] Data) { // allocate a buffer with uncompressed length to write compressed stream to byte[] tempBuffer = new byte[UncompressedLength]; int compressedLength; // ZLIB if (version > BgfFile.VERSION9) { // init streams MemoryStream destStream = new MemoryStream(tempBuffer, true); ZOutputStream destZ = new ZOutputStream(destStream, zlibConst.Z_BEST_COMPRESSION); // compress destZ.Write(Data, 0, Data.Length); destZ.Flush(); destZ.finish(); // update compressed length compressedLength = (int)destZ.TotalOut; // cleanup destStream.Dispose(); destZ.Dispose(); } // CRUSH else { #if WINCLR && X86 // compress to tempBuffer compressedLength = Crush32.Compress(Data, 0, tempBuffer, 0, (int)UncompressedLength); #else throw new Exception(ERRORCRUSHPLATFORM); #endif } // copy all bytes we actually used from tempBuffer to new PixelData byte[] newPixelData = new byte[compressedLength]; Array.Copy(tempBuffer, 0, newPixelData, 0, compressedLength); return(newPixelData); }
protected override void Dispose(bool disposing) { try { if (!disposing) { return; } _out.Dispose(); // TODO Parent context(s) should really be be closed explicitly _eiGen.Close(); _cGen.Close(); _sGen.Close(); } finally { base.Dispose(disposing); } }