示例#1
0
        public override void CopyTo(ReadOnlySpanAction <byte, object?> callback, object?state, int bufferSize)
        {
            // If we have been inherited into a subclass, the following implementation could be incorrect
            // since it does not call through to Read() which a subclass might have overridden.
            // To be safe we will only use this implementation in cases where we know it is safe to do so,
            // and delegate to our base class (which will call into Read) when we are not sure.
            if (GetType() != typeof(MemoryStream))
            {
                base.CopyTo(callback, state, bufferSize);
                return;
            }

            StreamHelpers.ValidateCopyToArgs(this, callback, bufferSize);

            // Retrieve a span until the end of the MemoryStream.
            ReadOnlySpan <byte> span = new ReadOnlySpan <byte>(_buffer, _position, _length - _position);

            _position = _length;

            // Invoke the callback, using our internal span and avoiding any
            // intermediary allocations.
            callback(span, state);
        }
示例#2
0
            public override void CopyTo(Stream destination, int bufferSize)
            {
                StreamHelpers.ValidateCopyToArgs(this, destination, bufferSize);

                // After we validate arguments this is a nop.
            }
示例#3
0
 /// <summary>
 /// Asynchronously reads the bytes from the current stream and writes them to another
 /// stream, using a specified buffer size and cancellation token.
 /// </summary>
 /// <param name="destination">The stream to which the contents of the current stream will be copied.</param>
 /// <param name="bufferSize"> The size, in bytes, of the buffer.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <returns></returns>
 public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
 {
     return(StreamHelpers.ArrayPoolCopyToAsync(this, destination, bufferSize, cancellationToken));
 }
示例#4
0
        public virtual Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
        {
            StreamHelpers.ValidateCopyToArgs(this, destination, bufferSize);

            return(CopyToAsyncInternal(destination, bufferSize, cancellationToken));
        }
 private void CopyTo(Stream destination, int bufferSize)
 {
     StreamHelpers.ValidateCopyToArgs(source, destination, bufferSize);
     CopyToInternal(destination, bufferSize);
 }
        private Task CopyToAsync(Stream destination, Int32 bufferSize, CancellationToken cancellationToken)
        {
            StreamHelpers.ValidateCopyToArgs(source, destination, bufferSize);

            return(CopyToAsyncInternal(destination, bufferSize, cancellationToken));
        }