| 1 | // 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. |
| 2 | |
| 3 | namespace WixToolset.Dtf.Compression |
| 4 | { |
| 5 | using System; |
| 6 | using System.IO; |
| 7 | |
| 8 | /// <summary> |
| 9 | /// This interface provides the methods necessary for the <see cref="CompressionEngine"/> to open |
| 10 | /// and close streams for archives and files. The implementor of this interface can use any |
| 11 | /// kind of logic to determine what kind of streams to open and where |
| 12 | /// </summary> |
| 13 | public interface IUnpackStreamContext |
| 14 | { |
| 15 | /// <summary> |
| 16 | /// Opens the archive stream for reading. |
| 17 | /// </summary> |
| 18 | /// <param name="archiveNumber">The zero-based index of the archive to open.</param> |
| 19 | /// <param name="archiveName">The name of the archive being opened.</param> |
| 20 | /// <param name="compressionEngine">Instance of the compression engine doing the operations.</param> |
| 21 | /// <returns>A stream from which archive bytes are read, or null to cancel extraction |
| 22 | /// of the archive.</returns> |
| 23 | /// <remarks> |
| 24 | /// When the first archive in a chain is opened, the name is not yet known, so the |
| 25 | /// provided value will be an empty string. When opening further archives, the |
| 26 | /// provided value is the next-archive name stored in the previous archive. This |
| 27 | /// name is often, but not necessarily, the same as the filename of the archive |
| 28 | /// package to be opened. |
| 29 | /// <para>If this method returns null, the archive engine will throw a |
| 30 | /// FileNotFoundException.</para> |
| 31 | /// </remarks> |
| 32 | Stream OpenArchiveReadStream(int archiveNumber, string archiveName, CompressionEngine compressionEngine); |
| 33 | |
| 34 | /// <summary> |
| 35 | /// Closes a stream where an archive package was read. |
| 36 | /// </summary> |
| 37 | /// <param name="archiveNumber">The archive number of the stream to close.</param> |
| 38 | /// <param name="archiveName">The name of the archive being closed.</param> |
| 39 | /// <param name="stream">The stream that was previously returned by |
| 40 | /// <see cref="OpenArchiveReadStream"/> and is now ready to be closed.</param> |
| 41 | void CloseArchiveReadStream(int archiveNumber, string archiveName, Stream stream); |
| 42 | |
| 43 | /// <summary> |
| 44 | /// Opens a stream for writing extracted file bytes. |
| 45 | /// </summary> |
| 46 | /// <param name="path">The path of the file within the archive. This is often, but |
| 47 | /// not necessarily, the same as the relative path of the file outside the archive.</param> |
| 48 | /// <param name="fileSize">The uncompressed size of the file to be extracted.</param> |
| 49 | /// <param name="lastWriteTime">The last write time of the file to be extracted.</param> |
| 50 | /// <returns>A stream where extracted file bytes are to be written, or null to skip |
| 51 | /// extraction of the file and continue to the next file.</returns> |
| 52 | /// <remarks> |
| 53 | /// The implementor may use the path, size and date information to dynamically |
| 54 | /// decide whether or not the file should be extracted. |
| 55 | /// </remarks> |
| 56 | Stream OpenFileWriteStream(string path, long fileSize, DateTime lastWriteTime); |
| 57 | |
| 58 | /// <summary> |
| 59 | /// Closes a stream where an extracted file was written. |
| 60 | /// </summary> |
| 61 | /// <param name="path">The path of the file within the archive.</param> |
| 62 | /// <param name="stream">The stream that was previously returned by <see cref="OpenFileWriteStream"/> |
| 63 | /// and is now ready to be closed.</param> |
| 64 | /// <param name="attributes">The attributes of the extracted file.</param> |
| 65 | /// <param name="lastWriteTime">The last write time of the file.</param> |
| 66 | /// <remarks> |
| 67 | /// The implementor may wish to apply the attributes and date to the newly-extracted file. |
| 68 | /// </remarks> |
| 69 | void CloseFileWriteStream(string path, Stream stream, FileAttributes attributes, DateTime lastWriteTime); |
| 70 | } |
| 71 | } |