I ended up using both advices, works just as I have imagined. Thanks everybody!
var in = std.io.getStdIn();
if (fileNamePointer.len != 0) {
const cwd = std.fs.cwd();
in = try cwd.openFile(fileNamePointer, .{});
}
defer in.close();
var bufRead = std.io.bufferedReader(in.reader());
const buffer = try allocator.alloc(u8, lineStop);
printHeader(lineStop, wordLength);
var offset: i64 = 0;
while (true) {
const len = try bufRead.reader().readAll(buffer);
if (len == 0) break;