FileReference.save () duplicates ByteArray

I ran into a memory issue with FileReference.save (). The My Flash application generates a large amount of data in real time and must save this data to a local file. As far as I understand, Flash 10 (unlike AIR) does not support streaming to a file. But even worse, FileReference.save () duplicates all data before saving. I was looking for a workaround to this doubled memory usage and thought of the following approach:

What if I pass my own ByteArray subclass as an argument to FileReference.save (), where this ByteArray subclass will override all read * () methods. The overridden read * () methods will wait for a portion of my file to be generated by my application, return that portion of the data, and immediately remove it from memory. I know how much data will be generated, so I could also override the length / bytesAvailable methods.

It would be possible? Could you please give me a hint how to do this? I created a subclass of ByteArray, registered an alias for it, passed an instance of that subclass to FileReference.save (), but somehow FileReference.save () seems to treat it in the same way as an instance of ByteArray, and doesn't call any from my overridden methods ...

Thanks for the help!

0


a source to share


2 answers


This is not what I've tried before, but you can try sending the data to a php application that will handle the ByteArray on the server, similar to storing the image on the server, so you will be using URLLoader.data using something like this:



http://www.zedia.net/2008/sending-bytearray-and-variables-to-server-side-script-at-the-same-time/

0


a source


This is an interesting idea. Perhaps you just need to add traces to the extended ByteArray to see how the FileReference # save () function internally works.

If he has any

while( originalByteArray.bytesAvailable ) 
  writeToSaveBuffer( originalByteArray.readByte() );

      

overrides can simply truncate the original buffer on each read, as you say, something like:



override function readByte() : uint {
  var b : uint = super.readByte();
  // Truncate the bytes (assuming bytesAvailable = length - removedBytes)
  length = length - bytesAvailable;
  return b;
}

      

On the other hand, if it works now, I think the original byte array will no longer be available afterwards in the application.

(I haven't tested this myself, truncation may require more work than the example)

0


a source







All Articles