aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Arnson <bob@firegiant.com>2020-02-13 21:32:33 -0500
committerBob Arnson <bob@firegiant.com>2020-02-13 21:43:43 -0500
commit6014309c4cb85bf2ee2efb034eafa956ca06a42a (patch)
tree172bf241a768aed6981d8f042d86f9a1f8d83989
parenta85f2e992a301abe5d2c0d58f07e7bc9692ff6e3 (diff)
downloadwix-6014309c4cb85bf2ee2efb034eafa956ca06a42a.tar.gz
wix-6014309c4cb85bf2ee2efb034eafa956ca06a42a.tar.bz2
wix-6014309c4cb85bf2ee2efb034eafa956ca06a42a.zip
Support reopening WixOutputs, to be able to read immediately after writing.
-rw-r--r--src/WixToolset.Data/WixOutput.cs23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/WixToolset.Data/WixOutput.cs b/src/WixToolset.Data/WixOutput.cs
index f27f7c77..43a43a6a 100644
--- a/src/WixToolset.Data/WixOutput.cs
+++ b/src/WixToolset.Data/WixOutput.cs
@@ -13,13 +13,15 @@ namespace WixToolset.Data
13 /// </summary> 13 /// </summary>
14 public class WixOutput : IDisposable 14 public class WixOutput : IDisposable
15 { 15 {
16 private readonly ZipArchive archive; 16 private ZipArchive archive;
17 private Stream stream;
17 private bool disposed; 18 private bool disposed;
18 19
19 private WixOutput(Uri uri, ZipArchive archive) 20 private WixOutput(Uri uri, ZipArchive archive, Stream stream)
20 { 21 {
21 this.Uri = uri; 22 this.Uri = uri;
22 this.archive = archive; 23 this.archive = archive;
24 this.stream = stream;
23 } 25 }
24 26
25 public Uri Uri { get; } 27 public Uri Uri { get; }
@@ -59,9 +61,9 @@ namespace WixToolset.Data
59 /// <returns>Newly created <c>WixOutput</c>.</returns> 61 /// <returns>Newly created <c>WixOutput</c>.</returns>
60 public static WixOutput Create(Uri uri, Stream stream) 62 public static WixOutput Create(Uri uri, Stream stream)
61 { 63 {
62 var archive = new ZipArchive(stream, ZipArchiveMode.Update); 64 var archive = new ZipArchive(stream, ZipArchiveMode.Update, leaveOpen: true);
63 65
64 return new WixOutput(uri, archive); 66 return new WixOutput(uri, archive, stream);
65 } 67 }
66 68
67 /// <summary> 69 /// <summary>
@@ -124,13 +126,13 @@ namespace WixToolset.Data
124 /// </summary> 126 /// </summary>
125 /// <param name="stream">Stream to read from.</param> 127 /// <param name="stream">Stream to read from.</param>
126 /// <returns>Loaded created <c>WixOutput</c>.</returns> 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)
128 { 130 {
129 try 131 try
130 { 132 {
131 var archive = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen); 133 var archive = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen: true);
132 134
133 return new WixOutput(uri, archive); 135 return new WixOutput(uri, archive, stream);
134 } 136 }
135 catch (InvalidDataException) 137 catch (InvalidDataException)
136 { 138 {
@@ -138,6 +140,12 @@ namespace WixToolset.Data
138 } 140 }
139 } 141 }
140 142
143 public void Reopen(ZipArchiveMode mode)
144 {
145 this.archive?.Dispose();
146 this.archive = new ZipArchive(this.stream, mode, leaveOpen: true);
147 }
148
141 /// <summary> 149 /// <summary>
142 /// Extracts an embedded file. 150 /// Extracts an embedded file.
143 /// </summary> 151 /// </summary>
@@ -224,6 +232,7 @@ namespace WixToolset.Data
224 if (disposing) 232 if (disposing)
225 { 233 {
226 this.archive?.Dispose(); 234 this.archive?.Dispose();
235 this.stream?.Dispose();
227 } 236 }
228 } 237 }
229 238