Re: Reading a binary file

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Thu, 17 Aug 2000 12:10:29 +1200, Jiri Babor wrote:

>Brian,
>
>Every time I trip over the get_bytes() function, I get a feeling
>Robert wrote it in a darker moment of his life, included it in get.e
>when he was not quite himself, and he has not looked at it since...
>
>When I want maximum speed, I determine the size of the file first,
>create a buffer and read the bytes using a simple for loop:
>
>----------------------------------------------------------------------
>    include file.e
>
>    sequence buffer
>    integer fi,len,o
>
>    fi = open(inFile, "rb")
>    if fi = -1 then
>        puts(1, "Input file " & inFile & " not found!")
>        abort(1)
>    end if
>
>    o = seek(fi,-1)         -- go to end of input file
>    len = where(fi)         -- get length of input file in bytes
>    o = seek(fi,0)          -- go back to beginning of input file
>    buffer = repeat(0, len) -- initialize your buffer
>    for i=1 to len do
>        buffer[i] = getc(fi)
>    end for
>    close(fi)
>----------------------------------------------------------------------
>
>jiri

Thanks jiri,

After looking at what 'get_bytes' actually does, I think your routine
should be in 'get.e'
I think most of the time you read a binary file, you want the whole thing
in a sequence so you can work with it...

Maybe Rob will consider this for the next release?

-- Brian

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu