Example #1
0
        private byte[] ProcessCompressedContent(string match, string replace)
        {
            try
            {
                // deal with gzipped data
                byte[] rawContent = CompressedStream.DeCompressContent(_content.ToArray(), _contentEncoding, _rawRead, BufferSize);

                // do Tranform on decompressed data
                rawContent = Replace(new List<byte>(rawContent), match, replace).ToArray();
                rawContent = _messageHandler.ProcessResponseContent(this, rawContent);

                // we have fixed up and decompressed the gzipped data, now gzip (compress) it back up
                using (MemoryStream rewriteStream = new MemoryStream())
                {
                    using (CompressedStream compressStream = new CompressedStream(_contentEncoding, rewriteStream, CompressionMode.Compress))
                    {
                        compressStream.Write(rawContent, 0, rawContent.Length);
                        compressStream.Flush();
                        rewriteStream.Flush();
                    }
                    return rewriteStream.ToArray();
                }
            }
            catch (Exception excp)
            {
                LogFactory.LogException(excp, "compression");
                // try to return just the raw data
                return _content.ToArray();
            }
        }