Ejemplo n.º 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>
        internal Stream OpenRead(string fileName)
        {
            Stream            archiveStream     = File.OpenRead(this.FullName);
            CompressionEngine compressionEngine = this.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));
        }
Ejemplo n.º 2
0
 internal void Unpack(
     string destDirectory,
     EventHandler <ArchiveProgressEventArgs> progressHandler)
 {
     using (CompressionEngine compressionEngine = this.CreateCompressionEngine())
     {
         compressionEngine.Progress += progressHandler;
         ArchiveFileStreamContext streamContext =
             new ArchiveFileStreamContext(this.FullName, destDirectory, null);
         streamContext.EnableOffsetOpen = true;
         compressionEngine.Unpack(streamContext, null);
     }
 }
Ejemplo n.º 3
0
        internal void UnpackFileSet(
            IDictionary <string, string> fileNames,
            string destDirectory,
            EventHandler <ArchiveProgressEventArgs> progressHandler)
        {
            if (fileNames == null)
            {
                throw new ArgumentNullException("fileNames");
            }

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