byChunk odd behavior?

Hanh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 22 00:17:41 PDT 2016


Hi all,

I'm trying to process a rather large file as an InputRange and 
run into something strange with byChunk / take.

void test() {
	auto file = new File("test.txt");
	auto input = file.byChunk(2).joiner;
	input.take(3).array;
	foreach (char c; input) {
		writeln(c);
	}
}

Let's say test.txt contains "123456".

The output will be
3
4
5
6

The "take" consumed one chunk from the file, but if I increase 
the chunk size to 4, then it won't.

It looks like if "take" spans two chunks, it affects the input 
range otherwise it doesn't.

Actually, what is the easiest way to read a large file as a 
stream? My file contains a bunch of serialized messages of 
variable length.

Thanks,
--h






More information about the Digitalmars-d-learn mailing list