protected override async Task <long> ReadStreamInternal(Stream stream, long?length) { await Task.CompletedTask.ConfigureAwait(false); if (ReadOnly) { throw new NotSupportedException(); } Stream.Position = 0; using (var skip = new SkipableStream(Stream, 0)) { long readed; try { readed = skip.ReadFromStream(stream, length); } catch (IOException) { WebServerLog.Add(ServerLogType.Information, GetType(), "Send", "Connection closed by remote Host"); readed = Stream.Position; } Stream.SetLength(readed); return(readed); } }
protected override async Task <long> WriteStreamInternal(Stream stream, long start, long?stop) { using (var skip = new SkipableStream(stream, start)) { long total = 0; foreach (var s in GetAllSources()) { if (stop != null && total >= stop.Value) { return(total); } var end = stop == null ? null : (long?)(stop.Value - total); var size = s.Length(); if (size == null) { total += await s.WriteStream(skip, 0, end).ConfigureAwait(false); } else { if (size.Value < skip.SkipBytes) { skip.Skip(size.Value); continue; } var leftSkip = skip.SkipBytes; skip.Skip(skip.SkipBytes); total += await s.WriteStream(skip, leftSkip, end).ConfigureAwait(false); } } return(total); } }
protected override async Task <long> WriteStreamInternal(Stream stream, long start, long?stop) { await Task.CompletedTask; Stream.Position = start; using (var skip = new SkipableStream(Stream, 0)) { try { return(skip.WriteToStream(stream, stop == null ? null : (long?)(stop.Value - start))); } catch (IOException) { WebServerLog.Add(ServerLogType.Information, GetType(), "Send", "Connection closed by remote Host"); return(Stream.Position - start); } } }