2019-08-17 09:58:17 -04: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-05 21:29:43 -04: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 09:58:17 -04:00
|
|
|
|
public static void ExportToFile(this Stream stream, string fileName)
|
|
|
|
|
{
|
|
|
|
|
using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Write))
|
|
|
|
|
{
|
2019-09-15 19:13:01 -04:00
|
|
|
|
stream.Position = 0;
|
2019-08-17 09:58:17 -04:00
|
|
|
|
stream.CopyTo(fileStream);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|