 			stream.next_in = data;
 			stream.next_in_index = 0;
 			
-			stream.next_out = uncompressed;
+			stream.next_out = chunk;
 			stream.next_out_index = 0;
 			
 			stream.avail_out = outBytesLength;

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

			
			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());
