public UnsyncFilterStream(Stream underlyingStream, UnsyncMode mode, bool leaveOpen) { if (underlyingStream == null) { throw new ArgumentNullException("underlyingStream"); } if (!Enum.IsDefined(typeof(UnsyncMode), mode)) { throw new InvalidEnumArgumentException("mode", (int)mode, typeof(UnsyncMode)); } this.underlyingStream = underlyingStream; this.mode = mode; this.leaveOpen = leaveOpen; }
public int ReadBytes(byte[] buffer, int offset, int count, UnsyncMode unsyncMode) { int bytesRead = 0; if (!Unsynchronization) { bytesRead = stream.Read(buffer, offset, count); position += bytesRead; } else { int i = 0; if (unsyncMode == UnsyncMode.CountExcludesUnsyncBytes) { for (; i < count; ++i) { buffer[offset + i] = ReadByte(); } } else if (unsyncMode == UnsyncMode.CountIncludesUnsyncBytes) { int unsyncBefore = UnsynchronizationCounter; for (; i + (UnsynchronizationCounter - unsyncBefore) < count; i++) { buffer[offset + i] = ReadByte(); } } else { throw new NotSupportedException("Unknown unsync mode"); } bytesRead = i; } return(bytesRead); }