diff --git a/CodeJam.Main/IO/StreamExtensions.cs b/CodeJam.Main/IO/StreamExtensions.cs index 6b62e3cf8..95e185ff3 100644 --- a/CodeJam.Main/IO/StreamExtensions.cs +++ b/CodeJam.Main/IO/StreamExtensions.cs @@ -1,4 +1,5 @@ -#if NET45_OR_GREATER || TARGETS_NETSTANDARD || TARGETS_NETCOREAPP // PUBLIC_API_CHANGES + +#if NET45_OR_GREATER || TARGETS_NETSTANDARD || TARGETS_NETCOREAPP // PUBLIC_API_CHANGES using System; using System.IO; using System.Text; @@ -83,9 +84,7 @@ public static string ReadAsString([NotNull] this Stream stream, [CanBeNull] Enco { // DO NOT dispose the reader using (var reader = stream.ToStreamReader(encoding, true)) - { return reader.ReadToEnd(); - } } /// @@ -100,9 +99,7 @@ public static async Task ReadAsStringAsync( { // DO NOT dispose the reader using (var reader = stream.ToStreamReader(encoding, true)) - { return await reader.ReadToEndAsync().ConfigureAwait(false); - } } /// @@ -112,13 +109,20 @@ public static async Task ReadAsStringAsync( [NotNull] public static byte[] ReadAsByteArray([NotNull] this Stream stream) { - // DO NOT dispose the reader - using (var reader = stream.ToBinaryReader(null, true)) + if (stream.CanSeek) + // DO NOT dispose underlying stream + using (var reader = stream.ToBinaryReader(null, true)) + { + var readCount = checked((int)(stream.Length - stream.Position)); + return reader.ReadBytes(readCount); + } + using (var tempStream = new MemoryStream()) { - var readCount = checked((int)(stream.Length - stream.Position)); - return reader.ReadBytes(readCount); + stream.CopyTo(tempStream); + return tempStream.ToArray(); } } } } -#endif + +#endif \ No newline at end of file diff --git a/CodeJam.Main/Readme.txt b/CodeJam.Main/Readme.txt index baa70d667..31c7ff430 100644 --- a/CodeJam.Main/Readme.txt +++ b/CodeJam.Main/Readme.txt @@ -1,6 +1,10 @@ -CodeJam 3.3.0 Release Notes +CodeJam 3.3.1 Release Notes --------------------------- +What's new in 3.3.1 +------------------- + * Fix StreamExtensions.ReadAsByteArray (non-seekable stream support) + What's new in 3.3.0 ------------------- * Add more string Invariant and Ordinal methods.