/// <exception cref="System.IO.IOException"/>
        /// <exception cref="TiffProcessingException"/>
        public static DirectoryList ReadMetadata(Stream stream)
        {
            // TIFF processing requires random access, as directories can be scattered throughout the byte sequence.
            // Stream does not support seeking backwards, so we wrap it with IndexedCapturingReader, which
            // buffers data from the stream as we seek forward.
            var directories = new List <Directory>();

            var handler = new ExifTiffHandler(directories);

            TiffReader.ProcessTiff(new IndexedCapturingReader(stream), handler);

            return(directories);
        }
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="TiffProcessingException"/>
        public static DirectoryList ReadMetadata(string filePath)
        {
            var directories = new List <Directory>();

            using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.RandomAccess))
            {
                var handler = new ExifTiffHandler(directories);
                TiffReader.ProcessTiff(new IndexedSeekingReader(stream), handler);
            }

            directories.Add(new FileMetadataReader().Read(filePath));

            return(directories);
        }