mirror of
https://github.com/aphrody-labs/NuGet.Client.git
synced 2026-10-14 13:29:05 +00:00
42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace Test.Utility
|
|
{
|
|
public static class StreamExtensions
|
|
{
|
|
public static byte[] ReadAllBytes(this Stream stream)
|
|
{
|
|
var memoryStream = stream as MemoryStream;
|
|
if (memoryStream != null)
|
|
{
|
|
return memoryStream.ToArray();
|
|
}
|
|
else
|
|
{
|
|
using (memoryStream = new MemoryStream())
|
|
{
|
|
stream.CopyTo(memoryStream);
|
|
return memoryStream.ToArray();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static Stream AsStream(this string value)
|
|
{
|
|
return new MemoryStream(Encoding.UTF8.GetBytes(value));
|
|
}
|
|
|
|
public static string ReadToEnd(this Stream stream)
|
|
{
|
|
using (var streamReader = new StreamReader(stream))
|
|
{
|
|
return streamReader.ReadToEnd();
|
|
}
|
|
}
|
|
}
|
|
}
|