public int GetBytes(byte[] source, int sourceIndex, int sourceCount, byte[] dest, int destIndex, bool flush) { if (source == null || source == null) { throw new ArgumentNullException(); } int bytes = 0; int newDestIndex = destIndex; for (int i = sourceIndex; i < sourceIndex + sourceCount; i++) { bool escape = false; bool newline = false; bool abort = false; byte b; try { b = source[i]; if (!escapeNextByte) { switch (b) { case escapeByte: i++; escape = true; if (i < sourceIndex + sourceCount) { b = source[i]; lineBytes++; } else { //what a pain, we cannot get the next character now, so //we set a flag to tell us to do it next time escapeNextByte = true; abort = true; } break; case 10: case 13: newline = true; break; } } } catch { throw new ArgumentOutOfRangeException(); } if ((!newline) && (!abort)) { b = DecodeByte(b, escape | escapeNextByte); escapeNextByte = false; try { dest[newDestIndex] = b; newDestIndex++; bytes++; } catch { throw new ArgumentException(); } } } if (flush) { crc32Hasher.TransformFinalBlock(dest, destIndex, bytes); storedHash = crc32Hasher.Hash; crc32Hasher = new CRC32(); } else { crc32Hasher.TransformBlock(dest, destIndex, bytes, dest, destIndex); } return(bytes); }