Reading file line by line in dart

dart, dart-io

Solution

This should read the file in chunks:

import 'dart:async';
import 'dart:io';
import 'dart:convert';

main() {
  var path = ...;
  new File(path)
    .openRead()
    .map(utf8.decode)
    .transform(new LineSplitter())
    .forEach((l) => print('line: $l'));
}

There isn't much documentation about this yet. Perhaps file a bug asking for more docs.

Problem

I'm trying to process large text files in a language Dart. The files have a size over 100 MB. I tried `readAsLines` and `readAsLinesSync` methods of `dart:io` library. Every time I run out of memory: `Exhausted heap space`. Is there a way to read a file line by line or byte by byte as in other languages​​?

Original source

Related problems