1
0
mirror of synced 2024-12-04 11:58:03 +01:00
Switch-Toolbox/Switch_Toolbox_Library/IO/Extensions/StreamExport.cs

36 lines
941 B
C#
Raw Normal View History

2019-08-17 15:58:17 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace Toolbox.Library.IO
{
public static class StreamExport
{
public static byte[] ToBytes(this Stream stream)
{
using (var reader = new FileReader(stream, true))
{
return reader.ReadBytes((int)stream.Length);
}
using (var memStream = new MemoryStream())
{
stream.CopyTo(memStream);
return memStream.ToArray();
}
}
2019-08-17 15:58:17 +02:00
public static void ExportToFile(this Stream stream, string fileName)
{
using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Write))
{
stream.Position = 0;
2019-08-17 15:58:17 +02:00
stream.CopyTo(fileStream);
}
}
}
}