Example #1
0
        /// <summary>
        /// Opens a file inside the archive for reading without actually
        /// extracting the file to disk.
        /// </summary>
        /// <param name="fileName">The name of the file in the archive. Also
        /// includes the internal path of the file, if any. File name matching
        /// is case-insensitive.</param>
        /// <returns>
        /// A stream for reading directly from the packed file. Like any stream
        /// this should be closed/disposed as soon as it is no longer needed.
        /// </returns>
        public Stream OpenRead(string fileName)
        {
            Stream            archiveStream     = File.OpenRead(FullName);
            CompressionEngine compressionEngine = CreateCompressionEngine();
            Stream            fileStream        = compressionEngine.Unpack(archiveStream, fileName);

            // Attach the archiveStream and compressionEngine to the
            // fileStream so they get disposed when the fileStream is disposed.
            return(new CargoStream(fileStream, archiveStream, compressionEngine));
        }
Example #2
0
 public void Unpack(
     string destDirectory,
     EventHandler <ArchiveProgressEventArgs> progressHandler)
 {
     using (CompressionEngine compressionEngine = CreateCompressionEngine()) {
         compressionEngine.Progress += progressHandler;
         ArchiveFileStreamContext streamContext =
             new ArchiveFileStreamContext(FullName, destDirectory, null);
         streamContext.EnableOffsetOpen = true;
         compressionEngine.Unpack(streamContext, null);
     }
 }
Example #3
0
        public void UnpackFileSet(
            IDictionary <string, string> fileNames,
            string destDirectory,
            EventHandler <ArchiveProgressEventArgs> progressHandler)
        {
            if (fileNames == null)
            {
                throw new ArgumentNullException("fileNames");
            }

            using (CompressionEngine compressionEngine = CreateCompressionEngine()) {
                compressionEngine.Progress += progressHandler;
                ArchiveFileStreamContext streamContext =
                    new ArchiveFileStreamContext(FullName, destDirectory, fileNames);
                streamContext.EnableOffsetOpen = true;
                compressionEngine.Unpack(
                    streamContext,
                    delegate(string match) { return(fileNames.ContainsKey(match)); });
            }
        }