0

I want to read 10 lines from the end of a big text file without loading the whole file in memory.

I wanted to try to use Open as explained here for Rebol In Rebol, what is the idiomatic way to read a text file line by line?

But Red doesn't have open function ?

user310291
  • 36,946
  • 82
  • 271
  • 487
  • Full I/O is not yet available in Red. Wait for 0.7.0 https://trello.com/b/FlQ6pzdB/red-tasks-overview – sqlab Nov 15 '17 at 11:21

2 Answers2

1

You can try a read/lines/seek/part %yourfile offset blocksize

But I have no clue. You have to test and adapt your offset and blocksize.

sqlab
  • 6,412
  • 1
  • 14
  • 29
  • There is a difference between Rebol's and Red's simple IO implementation of `read/part/lines`. On Rebol it reads number of lines given in `part` parameter. In Red, it first reads the `part` of the file and then splits it into `lines`. So `read/lines/part %file 2` returns different results for Red and Rebol. I think it will be fixed on Red when full IO is implemented. – endo64 Nov 15 '17 at 22:14
  • But with **read/lines/seek/part** you can write your own read-line function. But as GC is not available, there is probably no advantage compared to reading the whole file at once. Only if you know the filesize and want the last lines, then there are some advantages. – sqlab Nov 16 '17 at 13:11
1

Red doesn't have open function yet. Full IO support is planned for 0.7.0. So you have to either wait or use OS calls directly.

rebolek
  • 1,281
  • 7
  • 16