public Stream GetInputStream(uint index) { using (Stream stream = GetArchiveStream()) { using (InStreamWrapper wrapper = new InStreamWrapper(stream)) { using (ArchiveOpenCallback callback = new ArchiveOpenCallback(this, ParentLayer.Parent, file)) { ulong checkPos = 128 * 1024; if (archive.Open(wrapper, ref checkPos, callback) != 0) { throw new FileSystemException(String.Format("Could not open archive file \"{0}\".", ParentLayer)); } try { PropVariant sizeProperty = new PropVariant(); archive.GetProperty(index, ItemPropId.kpidSize, ref sizeProperty); // TODO: Limit memory usage. MemoryStream ms = new MemoryStream(sizeProperty.intValue); archive.Extract(new[] {index}, 1, 0, new ArchiveExtractCallback(ms)); ms.Seek(0, SeekOrigin.Begin); return ms; } finally { closeCommunicationLink(); } } } } }
public void GetStream(int index, out ISequentialInStream inStream) { inStream = new InStreamWrapper(content); }
public int GetStream(string name, out IInStream inStream) { IFileObject volumeFileObject = parent.resolveFile(Path.GetFileName(name)); if (volumeFileObject != null && volumeFileObject.exists()) { fileSystem.fireVolumeOpened(volumeFileObject); FileInfo file = parent.FileSystem.replicateFile(volumeFileObject, Selectors.SELECT_SELF); Stream fs = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read); streams.Add(fs); inStream = new InStreamWrapper(fs); return 0; } inStream = null; return 1; }
public override void init() { base.init(); try { IList strongRef = new ArrayList(100); using(Stream stream = GetArchiveStream()) { using(InStreamWrapper wrapper = new InStreamWrapper(stream)) { using (ArchiveOpenCallback callback = new ArchiveOpenCallback(this, ParentLayer.Parent, file)) { ulong checkPos = 128 * 1024; if (archive.Open(wrapper, ref checkPos, callback) != 0) { throw new FileSystemException(String.Format("Could not open Zip file \"{0}\".", ParentLayer)); } uint count = archive.GetNumberOfItems(); for (uint index = 0; index < count; index++) { PropVariant entryName = new PropVariant(); archive.GetProperty(index, ItemPropId.kpidPath, ref entryName); PropVariant hostSystem = new PropVariant(); archive.GetProperty(index, ItemPropId.kpidHostOS, ref hostSystem); string path = (string) entryName.GetObject(); if (String.Compare((string) hostSystem.GetObject(), "FAT", 0) == 0) { if (SevenZipFormat.SystemCodePage != SevenZipFormat.DefaultCodePage) { path = SevenZipFormat.DefaultEncoding.GetString(SevenZipFormat.SystemEncoding.GetBytes(path)); } } IFileName name = FileSystemManager.resolveName(RootName, VirtualFileSystem.Provider.UriParser.encode(path)); PropVariant isFolderProperty = new PropVariant(); archive.GetProperty(index, ItemPropId.kpidIsFolder, ref isFolderProperty); SevenZipFileObject fileObj; if ((bool) isFolderProperty.GetObject() && getFileFromCache(name) != null) { fileObj = (SevenZipFileObject) getFileFromCache(name); fileObj.Index = index; continue; } fileObj = createFileObject(name, index); putFileToCache(fileObj); strongRef.Add(fileObj); fileObj.holdObject(strongRef); SevenZipFileObject parent = null; for (IFileName parentName = name.Parent; parentName != null; fileObj = parent, parentName = parentName.Parent) { // Locate the parent parent = (SevenZipFileObject) getFileFromCache(parentName); if (parent == null) { parent = createFileObject(parentName, UInt32.MaxValue); putFileToCache(parent); strongRef.Add(parent); parent.holdObject(strongRef); } // Attach child to parent parent.attachChild(fileObj.Name); } } } } } } finally { closeCommunicationLink(); } }