Ejemplo n.º 1
0
        public void Compress(CompressionAlgorithm algorithm)
        {
            var buffer = memoryStream.ToArray();

            memoryStream.Close();
            var ms = new MemoryStream();

            var stream = algorithm == CompressionAlgorithm.Zlib
                ? new ZlibStream(ms, CompressionMode.Compress, true)
                : new DeflateStream(ms, CompressionMode.Compress, true);

            using (stream)
                stream.Write(buffer, 0, buffer.Length);

            memoryStream = ms;
            dataOutput   = new DataOutput(new AmfWriter(memoryStream, serializationContext));
            dataInput    = new DataInput(new AmfReader(memoryStream, serializationContext));
        }
Ejemplo n.º 2
0
        public void Compress(CompressionAlgorithm algorithm)
        {
            var buffer = memoryStream.ToArray();
            memoryStream.Close();
            var ms = new MemoryStream();

            var stream = algorithm == CompressionAlgorithm.Zlib
                ? new ZlibStream(ms, CompressionMode.Compress, true)
                : new DeflateStream(ms, CompressionMode.Compress, true);

            using (stream)
                stream.Write(buffer, 0, buffer.Length);

            memoryStream = ms;
            dataOutput = new DataOutput(new AmfWriter(memoryStream, serializationContext));
            dataInput = new DataInput(new AmfReader(memoryStream, serializationContext));
        }
Ejemplo n.º 3
0
 void ReloadStreams()
 {
     dataOutput = new DataOutput(new AmfWriter(memoryStream, serializationContext, objectEncoding));
     dataInput = new DataInput(new AmfReader(memoryStream, serializationContext));
 }
Ejemplo n.º 4
0
        public void Uncompress(CompressionAlgorithm algorithm)
        {
            Position = 0;
            var ms = new MemoryStream();
            var buffer = new byte[1024];

            // The zlib format is specified by RFC 1950. Zlib also uses deflate, plus 2 or 6 header bytes, and a 4 byte checksum at the end. 
            // The first 2 bytes indicate the compression method and flags. If the dictionary flag is set, then 4 additional bytes will follow.
            // Preset dictionaries aren't very common and we don't support them
            var deflateStream = algorithm == CompressionAlgorithm.Zlib
                ? new ZlibStream(memoryStream, CompressionMode.Decompress, false)
                : new DeflateStream(memoryStream, CompressionMode.Decompress, false);

            while (true)
            {
                var readCount = deflateStream.Read(buffer, 0, buffer.Length);
                if (readCount == 0)
                    break;
                ms.Write(buffer, 0, readCount);
            }

            memoryStream.Dispose();
            memoryStream = ms;
            memoryStream.Position = 0;
            dataOutput = new DataOutput(new AmfWriter(memoryStream, serializationContext));
            dataInput = new DataInput(new AmfReader(memoryStream, serializationContext));
        }
Ejemplo n.º 5
0
 void ReloadStreams()
 {
     dataOutput = new DataOutput(new AmfWriter(memoryStream, serializationContext, objectEncoding));
     dataInput  = new DataInput(new AmfReader(memoryStream, serializationContext));
 }
Ejemplo n.º 6
0
 private void ReloadStreams()
 {
     this._dataOutput = new DataOutput(new AmfWriter((Stream)this.MemoryStream, this._serializationContext, this._objectEncoding));
     this._dataInput  = new DataInput(new AmfReader((Stream)this.MemoryStream, this._serializationContext));
 }