Support reopening WixOutputs, to be able to read immediately after writing.
Bob Arnson committed
Feb 13, 2020 at 21:32 UTC
6014309c4cb85bf2ee2efb034eafa956ca06a42a
1 file changed
+16
-7
src/WixToolset.Data/WixOutput.cs
+16
-7
@@ -13,13 +13,15 @@ namespace WixToolset.Data
13
/// </summary>
14
public class WixOutput : IDisposable
15
{
16
- private readonly ZipArchive archive;
16
+ private ZipArchive archive;
17
+ private Stream stream;
18
private bool disposed;
19
19
- private WixOutput(Uri uri, ZipArchive archive)
20
+ private WixOutput(Uri uri, ZipArchive archive, Stream stream)
21
{
22
this.Uri = uri;
23
this.archive = archive;
24
+ this.stream = stream;
25
}
26
27
public Uri Uri { get; }
@@ -59,9 +61,9 @@ namespace WixToolset.Data
61
/// <returns>Newly created <c>WixOutput</c>.</returns>
62
public static WixOutput Create(Uri uri, Stream stream)
63
{
62
- var archive = new ZipArchive(stream, ZipArchiveMode.Update);
64
+ var archive = new ZipArchive(stream, ZipArchiveMode.Update, leaveOpen: true);
65
64
- return new WixOutput(uri, archive);
66
+ return new WixOutput(uri, archive, stream);
67
}
68
69
/// <summary>
@@ -124,13 +126,13 @@ namespace WixToolset.Data
126
/// </summary>
127
/// <param name="stream">Stream to read from.</param>
128
/// <returns>Loaded created <c>WixOutput</c>.</returns>
127
- public static WixOutput Read(Uri uri, Stream stream, bool leaveOpen = false)
129
+ public static WixOutput Read(Uri uri, Stream stream)
130
{
131
try
132
{
131
- var archive = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen);
133
+ var archive = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen: true);
134
133
- return new WixOutput(uri, archive);
135
+ return new WixOutput(uri, archive, stream);
136
}
137
catch (InvalidDataException)
138
{
@@ -138,6 +140,12 @@ namespace WixToolset.Data
140
}
141
}
142
143
+ public void Reopen(ZipArchiveMode mode)
144
+ {
145
+ this.archive?.Dispose();
146
+ this.archive = new ZipArchive(this.stream, mode, leaveOpen: true);
147
+ }
148
+
149
/// <summary>
150
/// Extracts an embedded file.
151
/// </summary>
@@ -224,6 +232,7 @@ namespace WixToolset.Data
232
if (disposing)
233
{
234
this.archive?.Dispose();
235
+ this.stream?.Dispose();
236
}
237
}
238