3 Replies Latest reply on Nov 8, 2009 11:32 PM by Santanu Karar

    FileStream readAhead ignored?


      I'm sure I'm overlooking something very simple here so feel free to poke fun and laugh at me when responding but it seems as if the readAhead property on FileStream is being ignored for me. Based on the documentation the readAhead "property specifies how much data an asynchronous stream attempts to read   beyond the current position." My assumption (I know this is where I'm doomed) was that the readAhead property acts as a throttle for the file async reading activities, so if you set the readAhead to 100 bytes it'll read 100 bytes, dispatch a ProgressEvent, assuming you grab those 100 bytes from the read buffer by executing one of the read functions in the progress event handler the filestream will grab the next 100 bytes. I'm not experiencing this so I'm guessing my assumptions are incorrect.


      I'm performing an async read on a 2K file (test) and set the readAhead to a smaller value (828). I receive a single progress event which indicates that the bytesLoaded is the entire 2K, so that kills one of my assumptions. I read the same byte size I indicated in the readAhead property (after verifying the bytes are available with bytesAvailable). That's it...no complete event, no close event, no more progress events. There is still bytes contained in the read buffer. If readAhead doesn't keep the FileStream from loading larger chunks what's the point of the property?


      I know I'm missing something here. Based on other "discussions" on this forum regarding the processing of large files it's suggested to set the readAhead property so the entire file isn't loaded into memory so it must work.


      I'm going to write a little app that ONLY reads in a file to isolate the code. I'm using FlexBuilder 3 (build 3.0.214193) if it matters. I guess I'm just hoping for comfirmation that the readAhead property actually does what I think it does based on somebody having used it as such.


      Thanks in advance.

        • 1. Re: FileStream readAhead ignored?
          dshmif Level 1

          I forgot to mention that before I set the readAhead property I was obtaining several progress events and the complete event once the file was fully read. However I need to process the data in chunks and was unable to keep up. That's when I stumbled on the property in question.

          • 2. Re: FileStream readAhead ignored?
            dshmif Level 1

            After isolating the code and running the basic example in the api for readAhead it seems that the intent is to only allow a single read from the file for the number of bytes specified by readAhead. Please sound off if I'm mistaken.

            • 3. Re: FileStream readAhead ignored?
              Santanu Karar Level 1

              I'm with dshmif, I also would like to know how this readAhead works..! if I would have a 200 bytes of files, and the readAhead is of 100 bytes, then in the bytesArray how do i stores the positions? will it be 1st time fileStream.readBytes(results, 0, 100), and then next time it would be fileStream.readBytes(results, 101, 100) ?


              I'm also a little confuse, since the progressEvent bytesAvailable shows the whole 200 bytes, and the readAhead example in the Adobe LiveDocs not quite satisfactory!


              Any help!?