Is there a function in Julia similar to Python's `tell`?

In addition to seek on open files, Python has a tell function … so I could save my place in a file and go back to it? Perhaps I am going about things wrong.

What I’m really trying to do is read in a structure from a file that is organized like this:

fh = open("myfile.bin")
c_length = ntoh(read(fh, UInt32))
c_type = read(fh, 4)
c_data = read(fh, c_length)
c_crc = ntoh(read(fh, UInt32))

# Then somehow fuse together c_length, c_type and c_crc,
# compute the CRC, then compare to c_crc.

To compute the CRC, I need to somehow fuse together c_length, c_type and c_data … which I had planned on doing with seek, but this won’t always happen at the beginning of the file … there are many such structures grouped together in the file. I also wanted to minimize the amount of reallocation of things.

Maybe refactor my CRC code to allow updating an on-going computation?

Maybe position I/O and Network · The Julia Language

6 Likes

Instead of dogmatically looking for tell :laughing: … thanks

You can also mark a stream and go back to the mark with reset.

5 Likes