protected byte[] ReadToEOF() { const int INITIAL_SIZE = 4096; const int MIN_SPACE = 1024; const int MAX_DELTA = 65536; int size = INITIAL_SIZE; var buf = new byte[size]; int len = 0; while (true) { if (len + MIN_SPACE > size) { size += size < MAX_DELTA ? size : MAX_DELTA; Array.Resize <byte>(ref buf, size); } int delta = TextStore.Read(buf, len, size - len); if (delta == -1) { Array.Resize <byte>(ref buf, len); return(buf); } len += delta; } }
protected byte[] ReadBySize(int size) { var buf = new byte[size]; int len = 0; while (len < size) { var delta = TextStore.Read(buf, len, size - len); if (delta == -1) { Array.Resize <byte>(ref buf, len); return(buf); } len += delta; } return(buf); }