//write_nonblock #endregion #region read, read_nonblock private static byte[] ReadAllBytes(RubyIO /*!*/ io) { var fixedBuffer = new byte[io.Length]; io.ReadBytes(fixedBuffer, 0, (int)io.Length); return(fixedBuffer); }
public static MutableString /*!*/ SystemRead(RubyIO /*!*/ self, [DefaultProtocol] int bytes) { var fixedBuffer = new byte[bytes]; int len = self.ReadBytes(fixedBuffer, 0, bytes); if (len == 0) { throw new EOFError("end of file reached"); } MutableString result = MutableString.CreateBinary(); result.Append(fixedBuffer, 0, len); return(result); }
public static MutableString /*!*/ Read(RubyIO /*!*/ self, [DefaultProtocol] int bytes, [DefaultProtocol, Optional] MutableString buffer) { self.AssertOpenedForReading(); if (self.IsEndOfStream()) { return(null); } if (buffer == null) { buffer = MutableString.CreateBinary(); } buffer.Clear(); if (!self.PreserveEndOfLines) { for (int i = 0; i < bytes; ++i) { int c = self.ReadByteNormalizeEoln(); if (c == -1) { return(buffer); } else { buffer.Append((byte)c); } } } else { var fixedBuffer = new byte[bytes]; bytes = self.ReadBytes(fixedBuffer, 0, bytes); buffer.Append(fixedBuffer, 0, bytes); } return(buffer); }
public static MutableString/*!*/ SystemRead(RubyIO/*!*/ self, [DefaultProtocol]int bytes) { var fixedBuffer = new byte[bytes]; int len = self.ReadBytes(fixedBuffer, 0, bytes); if (len == 0) { throw new EOFError("end of file reached"); } MutableString result = MutableString.CreateBinary(); result.Append(fixedBuffer, 0, len); return result; }
public static MutableString/*!*/ Read(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) { self.AssertOpenedForReading(); if (self.IsEndOfStream()) { return null; } if (buffer == null) { buffer = MutableString.CreateBinary(); } buffer.Clear(); if (!self.PreserveEndOfLines) { for (int i = 0; i < bytes; ++i) { int c = self.ReadByteNormalizeEoln(); if (c == -1) { return buffer; } else { buffer.Append((byte)c); } } } else { var fixedBuffer = new byte[bytes]; bytes = self.ReadBytes(fixedBuffer, 0, bytes); buffer.Append(fixedBuffer, 0, bytes); } return buffer; }
private static byte[]/*!*/ ReadAllBytes(RubyIO/*!*/ io) { var fixedBuffer = new byte[io.Length]; io.ReadBytes(fixedBuffer, 0, (int)io.Length); return fixedBuffer; }