Skip to content
Next Next commit
lateapexearlyspeed-issue-58383 Support unseekable filestream when Rea…
…dAllBytes[Async].
  • Loading branch information
lateapexearlyspeed committed Aug 31, 2021
commit b269ffeb5a1f21166c362a3d22a230157e8a375a
11 changes: 11 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/IO/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ public static byte[] ReadAllBytes(string path)
// bufferSize == 1 used to avoid unnecessary buffer in FileStream
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 1, FileOptions.SequentialScan))
{
if (!fs.CanSeek)
{
return ReadAllBytesUnknownLength(fs);
}

long fileLength = fs.Length;
if (fileLength > int.MaxValue)
{
Expand Down Expand Up @@ -729,6 +734,12 @@ private static async Task<string> InternalReadAllTextAsync(string path, Encoding
bool returningInternalTask = false;
try
{
if (!fs.CanSeek)
{
returningInternalTask = true;
return InternalReadAllBytesUnknownLengthAsync(fs, cancellationToken);
}

long fileLength = fs.Length;
if (fileLength > int.MaxValue)
{
Expand Down