stream static method
For parsing large files, stream streams the contents of file
and returns the split parts in chunks.
Note: If using a linebreak (\n
) as a splitter, it's a good idea to
include \r\n
before \n
, as Windows and various internet protocols
will automatically replace linebreaks with \r\n
for backwards
compatibility with legacy platforms. Not doing so shouldn't cause any
problems in most cases, but will leave strings with a hidden \r
character. \n\r
is also used as a line ending by some systems.
delimiters
can be provided as Strings and/or Delimiters to denote
blocks of text that shouldn't be parsed for splitters
.
If removeSplitters
is true
, each string part will be captured
without the splitting character(s), if false
, the splitter will
be included with the part. removeSplitters
must not be null
.
If trimParts
is true
, the parser will trim the whitespace around
each part when they are captured. trimParts
must not be null
.
chunkSize
represents the number of characters in each chunk, it
must not be null
and must be > 0
.
Implementation
static Stream<List<String>> stream(
File file, {
required List<String> splitters,
List<Object>? delimiters,
bool removeSplitters = true,
bool trimParts = false,
Converter<List<int>, String>? decoder,
}) {
assert(splitters.isNotEmpty);
assert(delimiters == null ||
delimiters.every(
(delimiter) => delimiter is String || delimiter is Delimiter));
final input = file.openRead();
return input.transform(decoder ?? utf8.decoder).transform(
StringSplitterConverter(
splitters: splitters,
delimiters: delimiters,
removeSplitters: removeSplitters,
trimParts: trimParts,
),
);
}