AesEncrypter.EncryptionManager.CopyFromStreamToStream C# (CSharp) Метод

CopyFromStreamToStream() приватный Метод

private CopyFromStreamToStream ( Stream fromStream, Stream toStream, int size, Action updateAction ) : void
fromStream Stream
toStream Stream
size int
updateAction Action
Результат void
        private void CopyFromStreamToStream(Stream fromStream, Stream toStream, int size, Action<string> updateAction)
        {
            byte[] buffer = new byte[1024 * 8];
            int totalRead = 0;

            while (true)
            {
                int numberRead = fromStream.Read(buffer, 0, buffer.Length);

                if (numberRead == 0)
                {
                    break;
                }
                else
                {
                    totalRead += numberRead;

                    if (updateAction != null)
                    {
                        string updateText = null;

                        float percentage = 100 * (totalRead / (float)size);
                        updateText = "Processing " + percentage.ToString("##") + "%";


                        string amountReadAsString = null;
                        if (totalRead < 1024)
                        {
                            amountReadAsString = totalRead.ToString() + " bytes";
                        }
                        else if (totalRead < 1024 * 1024)
                        {
                            amountReadAsString = ((float)totalRead / 1024).ToString("#") + "kb";
                        }
                        else
                        {
                            amountReadAsString = ((float)totalRead / (1024 * 1024)).ToString("#") + "mb";
                        }

                        if (!string.IsNullOrEmpty(updateText))
                        {
                            updateText += "\n";
                        }
                        updateText += amountReadAsString;

                        updateAction(updateText);
                    }

                    toStream.Write(buffer, 0, numberRead);
                }
            }
        }