public byte[] DecompressPacket(byte[] Payload, int Offset) { MemoryStream ms = new MemoryStream(Payload.GetUpperBound(0) - Offset); ms.Write(Payload, Offset, Payload.GetUpperBound(0) - Offset); ms.Seek(0, System.IO.SeekOrigin.Begin); ZInputStream zs = new ZInputStream(ms); int UncompressedSize; byte[] Uncompressed = new byte[4096]; try { UncompressedSize = zs.read(Uncompressed, 0, 4096); } catch { if (DEBUG) { Debug("DECOMPRESSION FAILURE"); } Array.Copy(Payload, Offset - 1, Uncompressed, 0, Payload.Length - (Offset - 1)); UncompressedSize = Payload.Length - (Offset - 1); } zs.Close(); zs.Dispose(); ms.Close(); ms.Dispose(); Array.Resize(ref Uncompressed, UncompressedSize); return(Uncompressed); }
/** * Return the uncompressed content. * * @return the uncompressed content * @throws CmsException if there is an exception uncompressing the data. */ public byte[] GetContent() { CompressedData comData = CompressedData.GetInstance(contentInfo.Content); ContentInfo content = comData.EncapContentInfo; Asn1OctetString bytes = (Asn1OctetString)content.Content; ZInputStream zIn = new ZInputStream(bytes.GetOctetStream()); try { return(CmsUtilities.StreamToByteArray(zIn)); } catch (IOException e) { throw new CmsException("exception reading compressed stream.", e); } finally { zIn.Dispose(); } }