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
|
|
|
|
|
{
|
2019-09-06 03:29:43 +02:00
|
|
|
|
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))
|
|
|
|
|
{
|
2019-09-16 01:13:01 +02:00
|
|
|
|
stream.Position = 0;
|
2019-08-17 15:58:17 +02:00
|
|
|
|
stream.CopyTo(fileStream);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|