public Stream ReadDataDirectory(ImageDataDirectory directory)
 {
     if (directory == null)
     {
         throw new ArgumentNullException(nameof(directory));
     }
     if (directory.VirtualAddress == 0 || directory.Size == 0)
     {
         throw new ArgumentOutOfRangeException(nameof(directory), "Directory does not contain data.");
     }
     return(_file.CreateViewStream(directory.VirtualAddress, directory.Size, MemoryMappedFileAccess.Read));
 }
        private static IReadOnlyDictionary <ImageDataDirectoryEntry, ImageDataDirectory> ReadDirectoryEntries(MemoryMappedViewAccessor view, long location, int count)
        {
            var dictionary      = new Dictionary <ImageDataDirectoryEntry, ImageDataDirectory>();
            var dataDirectories = new IMAGE_DATA_DIRECTORY[count];

            view.ReadArray(location, dataDirectories, 0, dataDirectories.Length);
            for (var i = 0; i < dataDirectories.Length; i++)
            {
                var entry = new ImageDataDirectory
                {
                    Size           = dataDirectories[i].Size,
                    VirtualAddress = dataDirectories[i].VirtualAddress
                };
                dictionary.Add((ImageDataDirectoryEntry)i, entry);
            }
            return(dictionary);
        }