2016-12-23 21:45:24 +00:00
|
|
|
|
using System.IO;
|
2014-08-09 12:58:04 +00:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
2014-12-02 06:26:25 +00:00
|
|
|
|
namespace NzbDrone.Common.Extensions
|
2014-08-09 12:58:04 +00:00
|
|
|
|
{
|
|
|
|
|
public static class ResourceExtensions
|
|
|
|
|
{
|
2015-10-03 17:45:26 +00:00
|
|
|
|
public static byte[] GetManifestResourceBytes(this Assembly assembly, string name)
|
2014-08-09 12:58:04 +00:00
|
|
|
|
{
|
|
|
|
|
var stream = assembly.GetManifestResourceStream(name);
|
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
|
var result = new byte[stream.Length];
|
2014-08-09 12:58:04 +00:00
|
|
|
|
var read = stream.Read(result, 0, result.Length);
|
|
|
|
|
|
|
|
|
|
if (read != result.Length)
|
|
|
|
|
{
|
|
|
|
|
throw new EndOfStreamException("Reached end of stream before reading enough bytes.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|