aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Data/NonClosingStreamWrapper.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Data/NonClosingStreamWrapper.cs')
-rw-r--r--src/WixToolset.Data/NonClosingStreamWrapper.cs105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/WixToolset.Data/NonClosingStreamWrapper.cs b/src/WixToolset.Data/NonClosingStreamWrapper.cs
new file mode 100644
index 00000000..53d17d4d
--- /dev/null
+++ b/src/WixToolset.Data/NonClosingStreamWrapper.cs
@@ -0,0 +1,105 @@
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
3namespace WixToolset.Data
4{
5 using System;
6 using System.IO;
7
8 /// <summary>
9 /// Wrapper around stream to prevent other streams (like BinaryReader/Writer) from prematurely
10 /// closing a parent stream.
11 /// </summary>
12 internal class NonClosingStreamWrapper : Stream
13 {
14 private Stream stream;
15
16 public NonClosingStreamWrapper(Stream stream)
17 {
18 this.stream = stream;
19 }
20
21 public override bool CanRead { get { return this.stream.CanRead; } }
22
23 public override bool CanSeek { get { return this.stream.CanSeek; } }
24
25 public override bool CanTimeout { get { return this.stream.CanTimeout; } }
26
27 public override bool CanWrite { get { return this.stream.CanWrite; } }
28
29 public override long Length { get { return this.stream.Length; } }
30
31 public override long Position { get { return this.stream.Position; } set { this.stream.Position = value; } }
32
33 public override int ReadTimeout { get { return this.stream.ReadTimeout; } set { this.stream.ReadTimeout = value; } }
34
35 public override int WriteTimeout { get { return this.stream.WriteTimeout; } set { this.stream.WriteTimeout = value; } }
36
37 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
38 {
39 return this.stream.BeginRead(buffer, offset, count, callback, state);
40 }
41
42 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
43 {
44 return this.stream.BeginWrite(buffer, offset, count, callback, state);
45 }
46
47 public override void Close()
48 {
49 // Do not pass through the call since this is what we are overriding.
50 }
51
52 protected override void Dispose(bool disposing)
53 {
54 if (disposing)
55 {
56 this.stream.Flush();
57 }
58 }
59
60 public override int EndRead(IAsyncResult asyncResult)
61 {
62 return this.stream.EndRead(asyncResult);
63 }
64
65 public override void EndWrite(IAsyncResult asyncResult)
66 {
67 this.stream.EndWrite(asyncResult);
68 }
69
70 public override void Flush()
71 {
72 this.stream.Flush();
73 }
74
75 public override int Read(byte[] buffer, int offset, int count)
76 {
77 return this.stream.Read(buffer, offset, count);
78 }
79
80 public override int ReadByte()
81 {
82 return this.stream.ReadByte();
83 }
84
85 public override long Seek(long offset, SeekOrigin origin)
86 {
87 return this.stream.Seek(offset, origin);
88 }
89
90 public override void SetLength(long value)
91 {
92 this.stream.SetLength(value);
93 }
94
95 public override void Write(byte[] buffer, int offset, int count)
96 {
97 this.stream.Write(buffer, offset, count);
98 }
99
100 public override void WriteByte(byte value)
101 {
102 this.stream.WriteByte(value);
103 }
104 }
105}