public void ExportEntry(string name, Stream output) { if (this.Entries.ContainsKey(name) == false) { throw new KeyNotFoundException(); } if (this.Entries[name] is StreamEntry) { var entry = (StreamEntry)this.Entries[name]; this.Stream.Seek(entry.Offset, SeekOrigin.Begin); if (entry.CompressionType == Packages.PackageCompressionType.Zlib) { // this is a hack until I fix zlib handling using (var memory = this.Stream.ReadToMemoryStream(entry.CompressedSize)) { var zlib = new InflaterInputStream(memory); output.WriteFromStream(zlib, entry.Size); } } else if (entry.CompressionType == Packages.PackageCompressionType.None) { output.WriteFromStream(this.Stream, entry.Size); } else { throw new InvalidOperationException(); } } else if (this.Entries[name] is MemoryEntry) { MemoryEntry entry = (MemoryEntry)this.Entries[name]; output.Write(entry.Data, 0, entry.Data.Length); } else if (this.Entries[name] is CopyFromFileEntry) { CopyFromFileEntry entry = (CopyFromFileEntry)this.Entries[name]; using (var input = File.Open(entry.Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { output.WriteFromStream(input, entry.Size); } } else { throw new InvalidOperationException(); } }
public void SetEntry(string name, string path) { if (this.IsSolid == true) { throw new NotSupportedException("cannot write to solid packages"); } else if (this.Stream.CanWrite == false) { throw new NotSupportedException("stream is not writable"); } if (this.Entries.ContainsKey(name) && this.Entries[name] is StreamEntry) { this.OriginalEntries[name] = (StreamEntry)this.Entries[name]; } CopyFromFileEntry entry = new CopyFromFileEntry(); entry.Path = path; entry.Size = (int)(new FileInfo(path).Length); this.Entries[name] = entry; }