Fastest way to read last line of text file

hi, i'm trying to read last line of file and will put the code inside a loop, is there any fastest way to do this

what i already try is :

let mmap = unsafe { Mmap::map(&file).expect("failed to map the file") };
&mmap[prev_len..now_len]

^ with that, i need to load a whole file to just get the last line

1 Like

Use Seek to read only the end of the file. You'll need to guess or search how long the line is, but there's no way around that.

With memory-mapped file you can also search from the end, e.g. mmap.rfind('\n').

6 Likes