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

◆ InternalReadAllBytesUnknownLengthAsync()

static async Task< byte[]> System.IO.File.InternalReadAllBytesUnknownLengthAsync ( FileStream fs,
CancellationToken cancellationToken )
inlinestaticprivate

Definition at line 773 of file File.cs.

774 {
775 byte[] rentedArray = ArrayPool<byte>.Shared.Rent(512);
776 try
777 {
778 int bytesRead = 0;
779 while (true)
780 {
781 if (bytesRead == rentedArray.Length)
782 {
783 uint num = (uint)(rentedArray.Length * 2);
784 if (num > 2147483591)
785 {
786 num = (uint)Math.Max(2147483591, rentedArray.Length + 1);
787 }
788 byte[] array = ArrayPool<byte>.Shared.Rent((int)num);
789 Buffer.BlockCopy(rentedArray, 0, array, 0, bytesRead);
790 byte[] array2 = rentedArray;
792 ArrayPool<byte>.Shared.Return(array2);
793 }
794 int num2 = await fs.ReadAsync(rentedArray.AsMemory(bytesRead), cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
795 if (num2 == 0)
796 {
797 break;
798 }
799 bytesRead += num2;
800 }
801 return rentedArray.AsSpan(0, bytesRead).ToArray();
802 }
803 finally
804 {
805 fs.Dispose();
806 ArrayPool<byte>.Shared.Return(rentedArray);
807 }
808 }

References System.array, System.Buffer.BlockCopy(), System.cancellationToken, and System.Math.Max().

Referenced by System.IO.File.ReadAllBytesAsync().