On Monday, 11 December 2017 at 20:51:41 UTC, Jordi Gutiérrez Hermoso wrote:
I'd like to read from a file, one byte at a time, without loading the whole file in memory.

I was hoping I could do something like

   auto f = File("somefile");
   foreach(c; f.byChar) {
       process(c);
   }

but there appears to be no such way to do it anymore. Instead, the stdlib seems to provide several functions to do chunked reads from the file where I have to manually manage the buffer. I see that D1 had a stream, but it's no longer here and I understand ranges are supposed to be used instead.

What's the explanation here? Why is there no more stream and what am I supposed to use instead? Do I really need to be manually managing the read buffer myself?

This should work;

 scope f = new MmFile("somefile");
   foreach(c; cast(string)f[]) {
       process(c);
   }

Reply via email to