Beispiel #1
0
        /// <summary>
        /// Reads an 'ar' archive file from the specified stream.
        /// </summary>
        /// <param name="stream">The stream to read 'ar' a archive file from.</param>
        /// <param name="options">The options used for reading this 'ar' file.</param>
        /// <returns>An instance of <see cref="ArArchiveFile"/> if the read was successful.</returns>
        /// <exception cref="ObjectFileException">In case of an invalid file.</exception>
        public static ArArchiveFile Read(Stream stream, ArArchiveFileReaderOptions options)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (!TryRead(stream, options, out var arFile, out var diagnostics))
            {
                throw new ObjectFileException("Invalid ar file", diagnostics);
            }

            return(arFile);
        }
Beispiel #2
0
        /// <summary>
        /// Tries to reads an 'ar' archive file from the specified stream.
        /// </summary>
        /// <param name="stream">The stream to read 'ar' a archive file from.</param>
        /// <param name="options">The options used for reading this 'ar' file.</param>
        /// <param name="arArchiveFile">The output 'ar' archive file if the read was successful.</param>
        /// <param name="diagnostics">The output associated diagnostics after reading the archive.</param>
        /// <returns><c>true</c> An instance of <see cref="ArArchiveFile"/> if the read was successful.</returns>
        public static bool TryRead(Stream stream, ArArchiveFileReaderOptions options, out ArArchiveFile arArchiveFile, out DiagnosticBag diagnostics)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            arArchiveFile = new ArArchiveFile {
                Kind = options.ArchiveKind
            };
            var reader = new ArArchiveFileReader(arArchiveFile, stream, options);

            diagnostics = reader.Diagnostics;
            reader.Read();

            return(!reader.Diagnostics.HasErrors);
        }
 internal ArArchiveFileReader(ArArchiveFile arArchiveFile, Stream stream, ArArchiveFileReaderOptions options) : base(stream)
 {
     ArArchiveFile = arArchiveFile;
     Options       = options;
     IsReadOnly    = options.IsReadOnly;
 }