| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- using System.Linq;
- using System.IO;
- namespace System.Fire.Container {
- public partial class ContainerList {
- /// <summary>
- /// Get the data as stream object that was stored in the container
- /// </summary>
- /// <param name="FileIndex">The container file index</param>
- /// <returns>Returns the extracted data as stream from the container</returns>
- public Stream GetStream(int FileIndex) {
- return this.GetStream(this._files[FileIndex]);
- }
- /// <summary>
- /// Get the data as stream object that was stored in the container
- /// </summary>
- /// <param name="File">The container file index</param>
- /// <returns>Returns the extracted data as stream from the container</returns>
- public Stream GetStream(ContainerFile File) {
- MemoryStream mem = new MemoryStream();
- BinaryWriter bw = new BinaryWriter(mem);
- long size = 0;
- for (int i = 0, c = File.NumChunks; i < c; i++) {
- byte[] b = this.ReadChunk(File.ChunkPos, i);
- if (size + b.Length > File.Size) {
- bw.Write(b.Take((int)(File.Size - size)).ToArray());
- size += File.Size - size;
- } else {
- bw.Write(b);
- size += b.Length;
- }
- }
- return mem;
- }
- }
- }
|