From 3f583916719eeef598d10a5d4e14ef14f008243b Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 11 May 2021 07:36:37 -0700 Subject: Merge Dtf --- .../BasicUnpackStreamContext.cs | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/dtf/WixToolset.Dtf.Compression/BasicUnpackStreamContext.cs (limited to 'src/dtf/WixToolset.Dtf.Compression/BasicUnpackStreamContext.cs') diff --git a/src/dtf/WixToolset.Dtf.Compression/BasicUnpackStreamContext.cs b/src/dtf/WixToolset.Dtf.Compression/BasicUnpackStreamContext.cs new file mode 100644 index 00000000..94d13b9c --- /dev/null +++ b/src/dtf/WixToolset.Dtf.Compression/BasicUnpackStreamContext.cs @@ -0,0 +1,90 @@ +// 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; + + /// + /// Stream context used to extract a single file from an archive into a memory stream. + /// + [SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable")] + public class BasicUnpackStreamContext : IUnpackStreamContext + { + private Stream archiveStream; + private Stream fileStream; + + /// + /// Creates a new BasicExtractStreamContext that reads from the specified archive stream. + /// + /// Archive stream to read from. + public BasicUnpackStreamContext(Stream archiveStream) + { + this.archiveStream = archiveStream; + } + + /// + /// Gets the stream for the extracted file, or null if no file was extracted. + /// + public Stream FileStream + { + get + { + return this.fileStream; + } + } + + /// + /// Opens the archive stream for reading. Returns a DuplicateStream instance, + /// so the stream may be virtually opened multiple times. + /// + /// The archive number to open (ignored; 0 is assumed). + /// The name of the archive being opened. + /// Instance of the compression engine doing the operations. + /// A stream from which archive bytes are read. + public Stream OpenArchiveReadStream(int archiveNumber, string archiveName, CompressionEngine compressionEngine) + { + return new DuplicateStream(this.archiveStream); + } + + /// + /// Does *not* close the stream. The archive stream should be managed by + /// the code that invokes the archive extraction. + /// + /// The archive number of the stream to close. + /// The name of the archive being closed. + /// The stream being closed. + public void CloseArchiveReadStream(int archiveNumber, string archiveName, Stream stream) + { + // Do nothing. + } + + /// + /// Opens a stream for writing extracted file bytes. The returned stream is a MemoryStream + /// instance, so the file is extracted straight into memory. + /// + /// Path of the file within the archive. + /// The uncompressed size of the file to be extracted. + /// The last write time of the file. + /// A stream where extracted file bytes are to be written. + public Stream OpenFileWriteStream(string path, long fileSize, DateTime lastWriteTime) + { + this.fileStream = new MemoryStream(new byte[fileSize], 0, (int) fileSize, true, true); + return this.fileStream; + } + + /// + /// Does *not* close the file stream. The file stream is saved in memory so it can + /// be read later. + /// + /// Path of the file within the archive. + /// The file stream to be closed. + /// The attributes of the extracted file. + /// The last write time of the file. + public void CloseFileWriteStream(string path, Stream stream, FileAttributes attributes, DateTime lastWriteTime) + { + // Do nothing. + } + } +} -- cgit v1.2.3-55-g6feb