/// <summary> /// Creates a new <see cref="PakFile"/> instance and loads the package from the source stream. /// </summary> /// <param name="stream">The source stream that contains the package data.</param> /// <exception cref="PakException"> /// Thrown when the specified <paramref name="stream"/> could not be loaded. /// </exception> /// <remarks> /// The source stream must support the ability to read and seek. /// </remarks> public PakFile(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } if (!stream.CanRead) { throw new ArgumentException("Stream must be able to read", "stream"); } if (!stream.CanSeek) { throw new ArgumentException("Stream must be able to seek", "stream"); } this.stream = stream; this.map = new HashMap <string, PakEntry>(); this.entries = new ArrayList <PakEntry>(); PakEntry entry; DataStream dataStream = new DataStream(stream); while (stream.Position < stream.Length) { try { entry = PakEntry.Deserialize(dataStream); } catch (Exception e) { throw new PakException(e.Message); } } }
/// <summary>Returns a list of all entries found within the <paramref name="stream"/>.</summary> /// <param name="stream">The source stream that contains the package data.</param> /// <exception cref="PakException"> /// Thrown when the specified <paramref name="stream"/> could not be loaded. /// </exception> /// <remarks> /// The source stream must support the ability to read and seek. /// </remarks> /// <returns> /// Returns a list of all entries found within the <paramref name="stream"/>. /// </returns> public static IList <PakEntry> GetEntries(Stream stream) { IList <PakEntry> entries = new ArrayList <PakEntry>(); DataStream dataStream = new DataStream(stream); while (stream.Position < stream.Length) { try { entries.Add(PakEntry.Deserialize(dataStream)); } catch (Exception e) { throw new PakException(e.Message); } } return(entries); }