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.
just playing around with this....
// --------------------
module test;
import std.stdio, std.file, std.exception;
void main()
{
string filename = "test.txt";
enforce(filename.exists, "Umm..that file does not exist!");
auto file = File(filename, "r");
char[] charBuf;
while (!file.eof())
{
charBuf = file.rawRead(new char[1]);
if(!file.eof())
process(cast(char)(charBuf[0]));
}
return;
}
void process(char someChar)
{
import std.ascii : isPrintable;
if( isPrintable(someChar) )
writeln("found a printable character: ", someChar);
else
writeln("found a non printable character");
}
// --------------------