public WriteWriteAsyncStream(IWriteAsyncStream stream, Func <Stream, Stream> writeStack) { _stream = stream; _ms = new MemoryStream(); _watcher = new WriteWatcherStream(_ms, () => { }); // We do this mostly so that the ms is not disposed _stack = writeStack(_watcher); }
/// <summary> /// Straight copy from the reader to the writer /// </summary> public static async Task CopyToAsync(this IReadAsyncStream readStream, IWriteAsyncStream writeStream, CancellationToken ct) { // We have the double exception catching to avoid the using() from hiding the inner exception Exception inner = null; try { using (readStream) { try { var buffer = new byte[BufferSize]; int read; do { ct.ThrowIfCancellationRequested(); read = await readStream.ReadAsync(buffer, 0, buffer.Length, ct).ConfigureAwait(false); if (read > 0) { ct.ThrowIfCancellationRequested(); await writeStream.WriteAsync(buffer, 0, read, ct).ConfigureAwait(false); } } while (read > 0); } catch (Exception e) { inner = e; throw; } } } catch (Exception) { if (inner != null) { throw inner; } else { throw; } } }
/// <summary> /// Straight copy from the reader to the writer /// </summary> public static async Task CopyToAsync(this IReadAsyncStream readStream, IWriteAsyncStream writeStream, CancellationToken ct) { // We have the double exception catching to avoid the using() from hiding the inner exception Exception inner = null; try { using (readStream) { try { var buffer = new byte[BufferSize]; int read; do { ct.ThrowIfCancellationRequested(); read = await readStream.ReadAsync(buffer, 0, buffer.Length, ct).ConfigureAwait(false); if (read > 0) { ct.ThrowIfCancellationRequested(); await writeStream.WriteAsync(buffer, 0, read, ct).ConfigureAwait(false); } } while (read > 0); } catch (Exception e) { inner = e; throw; } } } catch (Exception) { if (inner != null) { throw inner; } else throw; } }
public SecureStoreIndexOutput(string path, IWriteAsyncStream writeStream, Action onComplete) { _writeStream = writeStream; _onComplete = onComplete; _length = 0; }
public WriteWriteAsyncStream(IWriteAsyncStream stream, Func<Stream, Stream> writeStack) { _stream = stream; _ms = new MemoryStream(); _watcher = new WriteWatcherStream(_ms, () => { }); // We do this mostly so that the ms is not disposed _stack = writeStack(_watcher); }
/// <summary> /// Create a write stream that will transform any data (using streams) before passing it down to the underlying stream /// </summary> /// <param name="stream">Underlying write stream to pass transformed data</param> /// <param name="writeStack">Using the passed write stream, wrap to create your data transformations</param> /// <returns>A write stream</returns> public static IWriteAsyncStream AddTransformer(this IWriteAsyncStream stream, Func <Stream, Stream> writeStack) { return(new WriteWriteAsyncStream(stream, writeStack)); }