public static byte[] ReadAllBytes(string path) { byte[] result; using (VirtualFileStream virtualFileStream = Open(path)) { byte[] bytesBuf = new byte[virtualFileStream.Length]; if (virtualFileStream.Read(bytesBuf, 0, bytesBuf.Length) != bytesBuf.Length) { throw new EndOfStreamException(); } result = bytesBuf; } return(result); }
private static void PreloadFileToMemory(object obj) { PreloadFileToMemoryItem preloadFileToMemoryItem = (PreloadFileToMemoryItem)obj; try { using (VirtualFileStream virtualFileStream = VirtualFile.Open(preloadFileToMemoryItem.Path)) { byte[] bytesBuf = new byte[virtualFileStream.Length]; if (virtualFileStream.Read(bytesBuf, 0, bytesBuf.Length) != bytesBuf.Length) { throw new Exception("Unable to load all data."); } preloadFileToMemoryItem.data = bytesBuf; preloadFileToMemoryItem.loaded = true; } } catch (Exception ex) { preloadFileToMemoryItem.error = ex.Message; } }