Re: Reading a binary file

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

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

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

Search



Quick Links

User menu

Not signed in.

Misc Menu