Tanoda
ResourceUtils.cs
Go to the documentation of this file.
1using System;
2using System.IO;
3using System.Linq;
4using System.Reflection;
5
7{
11 public static class ResourceUtils
12 {
16 public static byte[] ReadAllBytes(this Stream input)
17 {
18 var buffer = new byte[16 * 1024];
19 using (var ms = new MemoryStream())
20 {
21 int read;
22 while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
23 ms.Write(buffer, 0, read);
24 return ms.ToArray();
25 }
26 }
27
35 public static byte[] GetEmbeddedResource(string resourceFileName, Assembly containingAssembly = null)
36 {
37 if (containingAssembly == null)
38 containingAssembly = Assembly.GetCallingAssembly();
39
40 var resourceName = containingAssembly.GetManifestResourceNames().Single(str => str.EndsWith(resourceFileName));
41
42 using (var stream = containingAssembly.GetManifestResourceStream(resourceName))
43 return ReadAllBytes(stream);
44 }
45 }
46}