Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ CopyToAsyncInternal()

async Task System.Security.Cryptography.CryptoStream.CopyToAsyncInternal ( Stream destination,
int bufferSize,
CancellationToken cancellationToken )
inlineprivate

Definition at line 588 of file CryptoStream.cs.

589 {
590 byte[] rentedBuffer = ArrayPool<byte>.Shared.Rent(bufferSize);
591 GCHandle pinHandle = GCHandle.Alloc(rentedBuffer, GCHandleType.Pinned);
592 try
593 {
594 int bytesRead;
595 do
596 {
597 bytesRead = await ReadAsync(rentedBuffer.AsMemory(0, bufferSize), cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
598 await destination.WriteAsync(rentedBuffer.AsMemory(0, bytesRead), cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
599 }
600 while (bytesRead > 0);
601 }
602 finally
603 {
604 CryptographicOperations.ZeroMemory(rentedBuffer.AsSpan(0, bufferSize));
605 pinHandle.Free();
606 }
607 ArrayPool<byte>.Shared.Return(rentedBuffer);
608 }
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
override Task< int > ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
Definition Task.cs:226
static GCHandle Alloc(object? value)
Definition GCHandle.cs:81

References System.Runtime.InteropServices.GCHandle.Alloc(), System.cancellationToken, System.Threading.Tasks.Task< TResult >.ConfigureAwait(), System.destination, System.Runtime.InteropServices.GCHandle.Free(), System.Security.Cryptography.CryptoStream.ReadAsync(), System.Buffers.ArrayPool< T >.Shared, and System.Security.Cryptography.CryptographicOperations.ZeroMemory().

Referenced by System.Security.Cryptography.CryptoStream.CopyToAsync().