 		{
 			data.position = 0;
 			var uncompressed:ByteArray = new ByteArray();
+			var chunk:ByteArray = new ByteArray();
 			var outBytesLength:int = data.length * 2;
 			
 			var err:int;

			data.position = 0;
			var compressed:ByteArray = new ByteArray();
			var err:int;
			var i:int = 0;
			var j:int = 0;
			
			trace("Zlib.compress. data.length: " + data.length);
			trace("Zlib.compress. data: " + data.toString());
			
			var stream:ZStream = new ZStream();

			err = stream.deflateInit(JZlib.Z_BEST_COMPRESSION);

			
			stream.next_in = data;
			stream.next_in_index = 0;
			stream.avail_in = data.length;
			
			stream.next_out = compressed;
			stream.next_out_index = 0;
			stream.avail_out = outLen;
			
			
			
			
			
			err = stream.deflate(JZlib.Z_SYNC_FLUSH);
			
			if (err != JZlib.Z_OK)
			{
				compressed = null;
				trace("Zlib.compress. Compression failed with return value : " + err);
			}
			
			
			// TODO: we need this, but why? zlib must be missing something
			
			if (compressed.length > 2)
			{
				compressed.position = compressed.length - 2;
				compressed.writeByte(0xFF);
				compressed.writeByte(0xFF);
			}
			
			
			
			trace("Zlib.compress. compressed.length: " + compressed.length);
			trace("Zlib.compress. compressed: " + compressed.toString());
