What should byteArray.writeUTF( event.result.toString() ); do byteArray.writeUTF( event.result.toString() ); ? The result of zlib.compress () is neither Unicode nor "UTF" (meaningless without a number after it !?); it is binary aka raw bytes; you must not decode it, encode it, or apply any other transformations to it. The receiver must immediately unpack the raw bytes that it receives in order to recover the data that was transferred to zlib.compress ().
Refresh . In what documentation do you have support that byteArray.uncompress() expects a true zlib stream, not a deflate stream i.e. zlib stream after you cut off the first 2 bytes and last 4)?
The Flex 3 ByteArray documentation gives the following example:
bytes.uncompress(CompressionAlgorithm.DEFLATE);
but it doesn’t uselessly say what the default value is (if any). If there is a default value, it is not documented anywhere, so it would be very useful to use
bytes.uncompress(CompressionAlgorithm.ZLIB);
to make it obvious what you intend.
And the docs talk about the writeUTFBytes method, not the writeUTF method. Are you sure you copy / paste the exact recipient code into your question?
Update 2
Thanks for the url. It looks like I took possession of the “help”, not the real documents: = (. A few points:
(1) Yes, there is an explicit inflate() method. However, uncompress DOES have an arg algorithm; it can be CompressionAlgorithm.ZLIB (by default) or CompressionAlgorithm.DEFLATE ... Interestingly, the latter, however, is only available in Adobe Air, and not in Flash Player. At least we know that calling uncompress () is OK, and we can return to the problem of getting raw bytes to the wire and again into the ByteArray instance.
(2) More importantly, exist as writeUTF (Writes the UTF-8 byte string to the byte stream. The UTF-8 byte string in bytes is written first as a 16-bit integer followed by bytes representing the characters of the string) and writeUTFBytes (writes a UTF-8 string to the byte stream. Like the writeUTF () method, but writeUTFBytes () is not a 16-bit string prefix).
Whatever the merits of delivering UTF8 encoded bytes (nil, IMHO), you do not need a 2-byte length prefix; using writeUTF () ensures that uncompress () will work.
Connecting to explorer: using Python print for binary data doesn’t seem like a good idea (if sys.stdout wasn’t running to run in raw mode that you didn’t show in your code).
It is similar to doing event.result.toString () getting a string (similar to a Python unicode object, yes / no?) - with what and with subsequent encoding in UTF-8 it seems unlikely to work.
Given that I did not know that flex exists until today, I really cannot help you. Here are a few more self-reliance suggestions in case anyone who knows more flexibility comes soon:
(1) Make some debugs. Start with a minimal XML document. Show repr(xml_doc) . Show repr(zlib_compress_output) . In the (shortened version) of your flex script, use the closest function / method for repr() , which you can find to show: event.result , event.result.toString() and the result of writeUTF*() . Make sure you understand the consequences of everything that can happen after zlib.compress (). Reading documents can help.
(2) See how you can get raw bytes from event.result.
NTN, John