using System.IO; namespace Crowdin.Plugin.Helpers.FileHelpers { public static class DownloadFileHelper { public static byte[] LoadSourceBytes(string filepath) { using (var fsSource = new FileStream(filepath, FileMode.Open, FileAccess.Read)) { // Read the source file into a byte array. var bytes = new byte[fsSource.Length]; var numBytesToRead = (int)fsSource.Length; var numBytesRead = 0; while (numBytesToRead > 0) { // Read may return anything from 0 to numBytesToRead. var n = fsSource.Read(bytes, numBytesRead, numBytesToRead); // Break when the end of the file is reached. if (n == 0) break; numBytesRead += n; numBytesToRead -= n; } return bytes; } } } }