Re: Reading Files Byte-For-Byte




<PulsarSL@xxxxxxxxx> wrote in message
> Norm Cook wrote:
> > A bit confusing here. You want to read the file byte by byte but you are
> > attempting to read the file into an array.
>
> Yea, some code I found did it this way, but since Larry said it's slow,
> I guess I'll abandon the array --


You have misunderstood my message:

>> Is this how I should be doing it?

> Yes, you don't really want to read the file byte by byte due to low performance.

But you did not post the code for a byte by byte method, you posted code
for a single read operation.

The method you showed was the more performant method, so that was
how you should proceed. Reading byte for byte (on larger files) is going
to be slower due simply to the additional commands required to accomplish
the task. You much rather want to read the whole file in one go, storing it
in an array for easy access. Please read my message again and see if it now
better answers your question. I provided the code example for completeness,
to show how it would look with declared variables and the use of FreeFile.
However, when working with files, error handling is also advised but was not
shown.

I think the misunderstanding came about due to your mentioning reading the
file byte by byte, but showing code that reads the entire file in one shot. Reading
byte for byte requires some looping mechanism, which was also posted, but
is going to be slower, again due to the sheer number of commands needed
to accomplish the task. The difference is not going to be very noticable on
smaller files, but reading the entire file into a single array will make for easier
processing later on, when you need to write out the data. Also note how
my example code converted the first to bytes into printable characters for
the Debug command. While that will work for bytes that fall within the range
of printable characters, you'll need to do something else if your file data falls
outside that range (which image data is certain to do).

LFS
.



Relevant Pages

  • Re: Really Stuck, Please Help
    ... I am not sure how to construct an array. ... Reading Master Log", of the "Copreco Master Log" workbook. ... Dim sourceBook As String ...
    (microsoft.public.excel.programming)
  • Re: Problem with a script
    ... a loop there becomes impractical. ... You still have them as uniquely named array indexes... ... writing the code twice will only ... reading your entire code and parsing it in their head, ...
    (comp.lang.php)
  • Re: Problem with a script
    ... Okay, so variables have unique labels, that doesn't mean they still couldn't be handled in a loop. ... You still have them as uniquely named array indexes... ... I believe that for the new guy this code would be readable, and identifying problems should really not be any more difficult with this, plus I think that it actually might save some time to write the actual code from the beginnig, even though it's not at it's final stage, instead of first writing everything spread out, and then rewriting the same code again cleaned. ... If you expect a person to spend an hour reading your entire code and parsing it in their head, you wont get any help and have to solve the problem by yourself. ...
    (comp.lang.php)
  • Re: Strange behavior when working with large files
    ... > The first time I read a file it will read into the array in about 2 ... The second time I try to read a file in it ... The file I'm reading here consists of 1.5 million lines (50MB all ... that Perl needs as more time as longer the lines are. ...
    (comp.lang.perl.misc)
  • Re: Sement fault
    ... > %someletter that many put after the commands? ... have to download/install the source code and wander through it looking ... or reading the code to find out what it does. ... Open standards. ...
    (alt.os.linux.suse)