Skip to content

FileLines

[Source]

Iterate over the lines in a file.

Returns lines without trailing line breaks. Advances the file cursor to the end of each line returned from next.

This class buffers the file contents to accumulate full lines. If the file does not contain linebreaks, the whole file content is read and buffered, which might exceed memory resources. Take care.

class ref FileLines is
  Iterator[String iso^] ref

Implements


Constructors

create

[Source]

Create a FileLines instance on a given file.

This instance returns lines from the position of the given file at the time this constructor is called. Later manipulation of the file position is not accounted for. As a result iterating with this class will always return the full file content without gaps or repeated lines.

min_read_size determines the minimum amount of bytes to read from the file in one go. This class keeps track of the line lengths in the current file and uses the length of the last line as amount of bytes to read next, but it will never read less than min_read_size.

new ref create(
  file: File ref,
  min_read_size: USize val = 256)
: FileLines ref^

Parameters

  • file: File ref
  • min_read_size: USize val = 256

Returns


Public Functions

has_next

[Source]

fun ref has_next()
: Bool val

Returns


next

[Source]

Returns the next line in the file.

fun ref next()
: String iso^ ?

Returns