Skip to main content
Participant
July 12, 2017
Question

Compressed ByteArray to string and back, how to do it?

  • July 12, 2017
  • 0 replies
  • 537 views

I would like to transfer compressed data with the ByteArray, I can add object to the ByteArray, compress them and get a compressed string of the data.

But I don't know how to revert the process, if I have the compress string of data, how can load it in a byte array decompress it and get the data?

var hw1:String="Hello World"; //My test data

var ba1:ByteArray = new ByteArray();

ba1.writeUTFBytes(hw1); //add test data to byte array

ba1.deflate();  //compress the byte array

var ser:String = ba1.toString(); //serialize the byte array to a compressed string

var ba2:ByteArray = new ByteArray();

ba2.writeUTFBytes(ser); //how to revert the serialized byte array in a byte array again?

ba2.inflate(); //decompress the byte array

var hw2:String=ba2.toString() //it should return my test data "Hello World"

This topic has been closed for replies.