dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Handling large files/data within an AIR application

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    2

    Handling large files/data within an AIR application

    I've run into some problems trying to handle large text files in AIR (300+ MB in size). I can open a filestream and read the file just fine and even store it into a string variable. the problem occurs when i try to manipulate this data. Im trying to get each line as an element in an array so i can manipulate this data.

    Here's what i've tried:
    1. read the file into a string variable and perform a split looking for the newline character (\n). this freezes the program

    2. i've tried reading the file in one byte at a time and putting each line into an array AS it is being read from the filestream. This not only takes long but eventually freezes.

    3. i've tried splitting the final string variable which contains the entire text file into chunks to process it separately.

    4. i've even tried putting the file contents into a sqlite database, but this also freezes.


    At this point, im not sure what my options are. Is AIR even equipped to manipulate data at this level? I could use a point in the right direction, any help is appreciated.

  2. #2
    Junior Member
    Join Date
    Sep 2009
    Posts
    2
    just thought i'd post an update, still no luck though.

    i tried to read the file contents into a string
    find the indexOf the first \n occurance and then push that first line into an array
    then i'd cut the array so it would no longer have that first line.
    and continue calling the function recursively until the string was completely turned into an array.

    this generated a stackoverflow error

  3. #3
    Junior Member
    Join Date
    Sep 2009
    Location
    Greece
    Posts
    6
    I 've searched the flex docs a little and this might help.

    The following code shows how to use the readAhead property to limit the amount of data read into a file to 100 bytes:

    PHP Code:
    import flash.filesystem.*;

    var 
    file:File File.desktopDirectory.resolvePath("test.txt");
    var 
    fileStream:FileStream = new FileStream();
    fileStream.readAhead 100;
    fileStream.addEventListener(ProgressEvent.PROGRESSreadProgressHandler)
    fileStream.openAsync(fileFileMode.READ);
    var 
    results:ByteArray;

    function 
    readProgressHandler(event:ProgressEvent):void {
        if (
    fileStream.bytesAvailable >= 100) {
            
    fileStream.readBytes(results0100);
        }

    Maybe it is best that you use 1024 bytes to read ahead.

    Also you can use readUTFBytes(length:uint):String

    So that you procees the file in parts and put each line in a different string inside an array.

    I hope this helps.
    Flash at its best! Desktop Quality Flash RPG
    http://www.gemstonedragon.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center