// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. namespace WixToolset.Dtf.Compression { using System; using System.IO; using System.Diagnostics.CodeAnalysis; /// /// This interface provides the methods necessary for the /// to open and close streams for archives /// and files. The implementor of this interface can use any kind of logic /// to determine what kind of streams to open and where. /// public interface IPackStreamContext { /// /// Gets the name of the archive with a specified number. /// /// The 0-based index of the archive /// within the chain. /// The name of the requested archive. May be an empty string /// for non-chained archives, but may never be null. /// The archive name is the name stored within the archive, used for /// identification of the archive especially among archive chains. That /// name is often, but not necessarily the same as the filename of the /// archive package. string GetArchiveName(int archiveNumber); /// /// Opens a stream for writing an archive package. /// /// The 0-based index of the archive within /// the chain. /// The name of the archive that was returned /// by . /// True if the stream should be truncated when /// opened (if it already exists); false if an existing stream is being /// re-opened for writing additional data. /// Instance of the compression engine /// doing the operations. /// A writable Stream where the compressed archive bytes will be /// written, or null to cancel the archive creation. /// /// If this method returns null, the archive engine will throw a /// FileNotFoundException. /// Stream OpenArchiveWriteStream( int archiveNumber, string archiveName, bool truncate, CompressionEngine compressionEngine); /// /// Closes a stream where an archive package was written. /// /// The 0-based index of the archive within /// the chain. /// The name of the archive that was previously /// returned by /// . /// A stream that was previously returned by /// and is now ready to be closed. /// /// If there is another archive package in the chain, then after this stream /// is closed a new stream will be opened. /// void CloseArchiveWriteStream(int archiveNumber, string archiveName, Stream stream); /// /// Opens a stream to read a file that is to be included in an archive. /// /// The path of the file within the archive. This is often, /// but not necessarily, the same as the relative path of the file outside /// the archive. /// Returned attributes of the opened file, to be /// stored in the archive. /// Returned last-modified time of the opened file, /// to be stored in the archive. /// A readable Stream where the file bytes will be read from before /// they are compressed, or null to skip inclusion of the file and continue to /// the next file. [SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters")] Stream OpenFileReadStream( string path, out FileAttributes attributes, out DateTime lastWriteTime); /// /// Closes a stream that has been used to read a file. /// /// The path of the file within the archive; the same as /// the path provided /// when the stream was opened. /// A stream that was previously returned by /// and is now ready to be closed. void CloseFileReadStream(string path, Stream stream); /// /// Gets extended parameter information specific to the compression /// format being used. /// /// Name of the option being requested. /// Parameters for the option; for per-file options, /// the first parameter is typically the internal file path. /// Option value, or null to use the default behavior. /// /// This method provides a way to set uncommon options during packaging, or a /// way to handle aspects of compression formats not supported by the base library. /// For example, this may be used by the zip compression library to /// specify different compression methods/levels on a per-file basis. /// The available option names, parameters, and expected return values /// should be documented by each compression library. /// object GetOption(string optionName, object[] parameters); } }