public string ReadLine ( [NotNull] Encoding encoding ) { if (Eof) { return(null); } using (MemoryStream result = new MemoryStream()) { byte found = 0; while (found == 0) { byte[] buffer = _current.Buffer; int stop = ReferenceEquals(_current, _last) ? _position : _chunkSize; int head = _read; for (; head < stop; head++) { byte c = buffer[head]; if (c == '\r' || c == '\n') { found = c; break; } } result.Write(buffer, _read, head - _read); _read = head; if (found != 0) { _read++; } else { if (!_Advance()) { break; } } } if (found == '\r') { if (Peek() == '\n') { ReadByte(); } } return(EncodingUtility.GetString(encoding, result.ToArray())); } }
public string ReadLine ( [NotNull] Encoding encoding ) { Code.NotNull(encoding, "encoding"); if (Eof) { return(null); } using (MemoryStream result = new MemoryStream()) { byte found = 0; while (found == 0) { while (_position < _limit) { byte one = _buffer[_position++]; if (one == '\r' || one == '\n') { found = one; break; } result.WriteByte(one); } if (found == 0 && !_Advance()) { break; } } if (found == '\r') { int peek = PeekByte(); if (peek == '\n') { ReadByte(); } } return(EncodingUtility.GetString(encoding, result.ToArray())); } }
public static string UnpackString ( [NotNull] Stream stream, [CanBeNull] Encoding encoding ) { Code.NotNull(stream, "stream"); if (encoding == null) { encoding = Encoding.UTF8; } byte[] bytes = UnpackBytes(stream); string result = EncodingUtility.GetString ( encoding, bytes ); return(result); }