public static MutableString/*!*/ SystemRead(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) {
var stream = self.GetReadableStream();
if (stream.DataBuffered) {
throw RubyExceptions.CreateIOError("sysread for buffered IO");
}
// We use Flush to simulate non-buffered IO.
// A better approach would be to create a parallel FileStream with
// System.IO.FileOptions.WriteThrough (which corresponds to FILE_FLAG_NO_BUFFERING), and also maybe
// System.IO.FileOptions.SequentialScan (FILE_FLAG_SEQUENTIAL_SCAN).
// TODO: sysopen does that?
stream.Flush();
var result = Read(self, bytes, buffer);
if (result == null) {
throw new EOFError("end of file reached");
}
return result;
}