nClam.ClamClient.SendStreamFileChunksAsync C# (CSharp) 메소드

SendStreamFileChunksAsync() 개인적인 메소드

Helper method to send a byte array over the wire to the ClamAV server, split up in chunks.
private SendStreamFileChunksAsync ( Stream sourceStream, Stream clamStream, CancellationToken cancellationToken ) : Task
sourceStream Stream The stream to send to the ClamAV server.
clamStream Stream The communication channel to the ClamAV server.
cancellationToken CancellationToken
리턴 Task
        private async Task SendStreamFileChunksAsync(Stream sourceStream, Stream clamStream, CancellationToken cancellationToken)
        {
            var size = MaxChunkSize;
            var bytes = new byte[size];

            while ((size = await sourceStream.ReadAsync(bytes, 0, size, cancellationToken).ConfigureAwait(false)) > 0)
            {
                if (sourceStream.Position > MaxStreamSize)
                {
                    throw new MaxStreamSizeExceededException(MaxStreamSize);
                }

                var sizeBytes = BitConverter.GetBytes(System.Net.IPAddress.HostToNetworkOrder(size));  //convert size to NetworkOrder!
                await clamStream.WriteAsync(sizeBytes, 0, sizeBytes.Length, cancellationToken).ConfigureAwait(false);
                await clamStream.WriteAsync(bytes, 0, size, cancellationToken).ConfigureAwait(false);
            }

            var newMessage = BitConverter.GetBytes(0);
            await clamStream.WriteAsync(newMessage, 0, newMessage.Length, cancellationToken).ConfigureAwait(false);
        }