InflaterInputStream.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. // InflaterInputStream.cs
  2. //
  3. // Copyright (C) 2001 Mike Krueger
  4. // Copyright (C) 2004 John Reilly
  5. //
  6. // This file was translated from java, it was part of the GNU Classpath
  7. // Copyright (C) 2001 Free Software Foundation, Inc.
  8. //
  9. // This program is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU General Public License
  11. // as published by the Free Software Foundation; either version 2
  12. // of the License, or (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with this program; if not, write to the Free Software
  21. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. //
  23. // Linking this library statically or dynamically with other modules is
  24. // making a combined work based on this library. Thus, the terms and
  25. // conditions of the GNU General Public License cover the whole
  26. // combination.
  27. //
  28. // As a special exception, the copyright holders of this library give you
  29. // permission to link this library with independent modules to produce an
  30. // executable, regardless of the license terms of these independent
  31. // modules, and to copy and distribute the resulting executable under
  32. // terms of your choice, provided that you also meet, for each linked
  33. // independent module, the terms and conditions of the license of that
  34. // module. An independent module is a module which is not derived from
  35. // or based on this library. If you modify this library, you may extend
  36. // this exception to your version of the library, but you are not
  37. // obligated to do so. If you do not wish to do so, delete this
  38. // exception statement from your version.
  39. // HISTORY
  40. // 11-08-2009 GeoffHart T9121 Added Multi-member gzip support
  41. using System;
  42. using System.IO;
  43. #if !NETCF_1_0
  44. using System.Security.Cryptography;
  45. #endif
  46. namespace CommonMPQ.SharpZipLib.Zip.Compression.Streams
  47. {
  48. /// <summary>
  49. /// An input buffer customised for use by <see cref="InflaterInputStream"/>
  50. /// </summary>
  51. /// <remarks>
  52. /// The buffer supports decryption of incoming data.
  53. /// </remarks>
  54. public class InflaterInputBuffer
  55. {
  56. #region Constructors
  57. /// <summary>
  58. /// Initialise a new instance of <see cref="InflaterInputBuffer"/> with a default buffer size
  59. /// </summary>
  60. /// <param name="stream">The stream to buffer.</param>
  61. public InflaterInputBuffer(Stream stream) : this(stream , 4096)
  62. {
  63. }
  64. /// <summary>
  65. /// Initialise a new instance of <see cref="InflaterInputBuffer"/>
  66. /// </summary>
  67. /// <param name="stream">The stream to buffer.</param>
  68. /// <param name="bufferSize">The size to use for the buffer</param>
  69. /// <remarks>A minimum buffer size of 1KB is permitted. Lower sizes are treated as 1KB.</remarks>
  70. public InflaterInputBuffer(Stream stream, int bufferSize)
  71. {
  72. inputStream = stream;
  73. if ( bufferSize < 1024 ) {
  74. bufferSize = 1024;
  75. }
  76. rawData = new byte[bufferSize];
  77. clearText = rawData;
  78. }
  79. #endregion
  80. /// <summary>
  81. /// Get the length of bytes bytes in the <see cref="RawData"/>
  82. /// </summary>
  83. public int RawLength
  84. {
  85. get {
  86. return rawLength;
  87. }
  88. }
  89. /// <summary>
  90. /// Get the contents of the raw data buffer.
  91. /// </summary>
  92. /// <remarks>This may contain encrypted data.</remarks>
  93. public byte[] RawData
  94. {
  95. get {
  96. return rawData;
  97. }
  98. }
  99. /// <summary>
  100. /// Get the number of useable bytes in <see cref="ClearText"/>
  101. /// </summary>
  102. public int ClearTextLength
  103. {
  104. get {
  105. return clearTextLength;
  106. }
  107. }
  108. /// <summary>
  109. /// Get the contents of the clear text buffer.
  110. /// </summary>
  111. public byte[] ClearText
  112. {
  113. get {
  114. return clearText;
  115. }
  116. }
  117. /// <summary>
  118. /// Get/set the number of bytes available
  119. /// </summary>
  120. public int Available
  121. {
  122. get { return available; }
  123. set { available = value; }
  124. }
  125. /// <summary>
  126. /// Call <see cref="Inflater.SetInput(byte[], int, int)"/> passing the current clear text buffer contents.
  127. /// </summary>
  128. /// <param name="inflater">The inflater to set input for.</param>
  129. public void SetInflaterInput(Inflater inflater)
  130. {
  131. if ( available > 0 ) {
  132. inflater.SetInput(clearText, clearTextLength - available, available);
  133. available = 0;
  134. }
  135. }
  136. /// <summary>
  137. /// Fill the buffer from the underlying input stream.
  138. /// </summary>
  139. public void Fill()
  140. {
  141. rawLength = 0;
  142. int toRead = rawData.Length;
  143. while (toRead > 0) {
  144. int count = inputStream.Read(rawData, rawLength, toRead);
  145. if ( count <= 0 ) {
  146. break;
  147. }
  148. rawLength += count;
  149. toRead -= count;
  150. }
  151. #if !NETCF_1_0
  152. if ( cryptoTransform != null ) {
  153. clearTextLength = cryptoTransform.TransformBlock(rawData, 0, rawLength, clearText, 0);
  154. }
  155. else
  156. #endif
  157. {
  158. clearTextLength = rawLength;
  159. }
  160. available = clearTextLength;
  161. }
  162. /// <summary>
  163. /// Read a buffer directly from the input stream
  164. /// </summary>
  165. /// <param name="buffer">The buffer to fill</param>
  166. /// <returns>Returns the number of bytes read.</returns>
  167. public int ReadRawBuffer(byte[] buffer)
  168. {
  169. return ReadRawBuffer(buffer, 0, buffer.Length);
  170. }
  171. /// <summary>
  172. /// Read a buffer directly from the input stream
  173. /// </summary>
  174. /// <param name="outBuffer">The buffer to read into</param>
  175. /// <param name="offset">The offset to start reading data into.</param>
  176. /// <param name="length">The number of bytes to read.</param>
  177. /// <returns>Returns the number of bytes read.</returns>
  178. public int ReadRawBuffer(byte[] outBuffer, int offset, int length)
  179. {
  180. if ( length < 0 ) {
  181. throw new ArgumentOutOfRangeException("length");
  182. }
  183. int currentOffset = offset;
  184. int currentLength = length;
  185. while ( currentLength > 0 ) {
  186. if ( available <= 0 ) {
  187. Fill();
  188. if (available <= 0) {
  189. return 0;
  190. }
  191. }
  192. int toCopy = Math.Min(currentLength, available);
  193. System.Array.Copy(rawData, rawLength - (int)available, outBuffer, currentOffset, toCopy);
  194. currentOffset += toCopy;
  195. currentLength -= toCopy;
  196. available -= toCopy;
  197. }
  198. return length;
  199. }
  200. /// <summary>
  201. /// Read clear text data from the input stream.
  202. /// </summary>
  203. /// <param name="outBuffer">The buffer to add data to.</param>
  204. /// <param name="offset">The offset to start adding data at.</param>
  205. /// <param name="length">The number of bytes to read.</param>
  206. /// <returns>Returns the number of bytes actually read.</returns>
  207. public int ReadClearTextBuffer(byte[] outBuffer, int offset, int length)
  208. {
  209. if ( length < 0 ) {
  210. throw new ArgumentOutOfRangeException("length");
  211. }
  212. int currentOffset = offset;
  213. int currentLength = length;
  214. while ( currentLength > 0 ) {
  215. if ( available <= 0 ) {
  216. Fill();
  217. if (available <= 0) {
  218. return 0;
  219. }
  220. }
  221. int toCopy = Math.Min(currentLength, available);
  222. Array.Copy(clearText, clearTextLength - (int)available, outBuffer, currentOffset, toCopy);
  223. currentOffset += toCopy;
  224. currentLength -= toCopy;
  225. available -= toCopy;
  226. }
  227. return length;
  228. }
  229. /// <summary>
  230. /// Read a <see cref="byte"/> from the input stream.
  231. /// </summary>
  232. /// <returns>Returns the byte read.</returns>
  233. public int ReadLeByte()
  234. {
  235. if (available <= 0) {
  236. Fill();
  237. if (available <= 0) {
  238. throw new ZipException("EOF in header");
  239. }
  240. }
  241. byte result = rawData[rawLength - available];
  242. available -= 1;
  243. return result;
  244. }
  245. /// <summary>
  246. /// Read an <see cref="short"/> in little endian byte order.
  247. /// </summary>
  248. /// <returns>The short value read case to an int.</returns>
  249. public int ReadLeShort()
  250. {
  251. return ReadLeByte() | (ReadLeByte() << 8);
  252. }
  253. /// <summary>
  254. /// Read an <see cref="int"/> in little endian byte order.
  255. /// </summary>
  256. /// <returns>The int value read.</returns>
  257. public int ReadLeInt()
  258. {
  259. return ReadLeShort() | (ReadLeShort() << 16);
  260. }
  261. /// <summary>
  262. /// Read a <see cref="long"/> in little endian byte order.
  263. /// </summary>
  264. /// <returns>The long value read.</returns>
  265. public long ReadLeLong()
  266. {
  267. return (uint)ReadLeInt() | ((long)ReadLeInt() << 32);
  268. }
  269. #if !NETCF_1_0
  270. /// <summary>
  271. /// Get/set the <see cref="ICryptoTransform"/> to apply to any data.
  272. /// </summary>
  273. /// <remarks>Set this value to null to have no transform applied.</remarks>
  274. public ICryptoTransform CryptoTransform
  275. {
  276. set {
  277. cryptoTransform = value;
  278. if ( cryptoTransform != null ) {
  279. if ( rawData == clearText ) {
  280. if ( internalClearText == null ) {
  281. internalClearText = new byte[rawData.Length];
  282. }
  283. clearText = internalClearText;
  284. }
  285. clearTextLength = rawLength;
  286. if ( available > 0 ) {
  287. cryptoTransform.TransformBlock(rawData, rawLength - available, available, clearText, rawLength - available);
  288. }
  289. } else {
  290. clearText = rawData;
  291. clearTextLength = rawLength;
  292. }
  293. }
  294. }
  295. #endif
  296. #region Instance Fields
  297. int rawLength;
  298. byte[] rawData;
  299. int clearTextLength;
  300. byte[] clearText;
  301. #if !NETCF_1_0
  302. byte[] internalClearText;
  303. #endif
  304. int available;
  305. #if !NETCF_1_0
  306. ICryptoTransform cryptoTransform;
  307. #endif
  308. Stream inputStream;
  309. #endregion
  310. }
  311. /// <summary>
  312. /// This filter stream is used to decompress data compressed using the "deflate"
  313. /// format. The "deflate" format is described in RFC 1951.
  314. ///
  315. /// This stream may form the basis for other decompression filters, such
  316. /// as the <see cref="CommonMPQ.SharpZipLib.GZip.GZipInputStream">GZipInputStream</see>.
  317. ///
  318. /// Author of the original java version : John Leuner.
  319. /// </summary>
  320. public class InflaterInputStream : Stream
  321. {
  322. #region Constructors
  323. /// <summary>
  324. /// Create an InflaterInputStream with the default decompressor
  325. /// and a default buffer size of 4KB.
  326. /// </summary>
  327. /// <param name = "baseInputStream">
  328. /// The InputStream to read bytes from
  329. /// </param>
  330. public InflaterInputStream(Stream baseInputStream)
  331. : this(baseInputStream, new Inflater(), 4096)
  332. {
  333. }
  334. /// <summary>
  335. /// Create an InflaterInputStream with the specified decompressor
  336. /// and a default buffer size of 4KB.
  337. /// </summary>
  338. /// <param name = "baseInputStream">
  339. /// The source of input data
  340. /// </param>
  341. /// <param name = "inf">
  342. /// The decompressor used to decompress data read from baseInputStream
  343. /// </param>
  344. public InflaterInputStream(Stream baseInputStream, Inflater inf)
  345. : this(baseInputStream, inf, 4096)
  346. {
  347. }
  348. /// <summary>
  349. /// Create an InflaterInputStream with the specified decompressor
  350. /// and the specified buffer size.
  351. /// </summary>
  352. /// <param name = "baseInputStream">
  353. /// The InputStream to read bytes from
  354. /// </param>
  355. /// <param name = "inflater">
  356. /// The decompressor to use
  357. /// </param>
  358. /// <param name = "bufferSize">
  359. /// Size of the buffer to use
  360. /// </param>
  361. public InflaterInputStream(Stream baseInputStream, Inflater inflater, int bufferSize)
  362. {
  363. if (baseInputStream == null) {
  364. throw new ArgumentNullException("baseInputStream");
  365. }
  366. if (inflater == null) {
  367. throw new ArgumentNullException("inflater");
  368. }
  369. if (bufferSize <= 0) {
  370. throw new ArgumentOutOfRangeException("bufferSize");
  371. }
  372. this.baseInputStream = baseInputStream;
  373. this.inf = inflater;
  374. inputBuffer = new InflaterInputBuffer(baseInputStream, bufferSize);
  375. }
  376. #endregion
  377. /// <summary>
  378. /// Get/set flag indicating ownership of underlying stream.
  379. /// When the flag is true <see cref="Close"/> will close the underlying stream also.
  380. /// </summary>
  381. /// <remarks>
  382. /// The default value is true.
  383. /// </remarks>
  384. public bool IsStreamOwner
  385. {
  386. get { return isStreamOwner; }
  387. set { isStreamOwner = value; }
  388. }
  389. /// <summary>
  390. /// Skip specified number of bytes of uncompressed data
  391. /// </summary>
  392. /// <param name ="count">
  393. /// Number of bytes to skip
  394. /// </param>
  395. /// <returns>
  396. /// The number of bytes skipped, zero if the end of
  397. /// stream has been reached
  398. /// </returns>
  399. /// <exception cref="ArgumentOutOfRangeException">
  400. /// <paramref name="count">The number of bytes</paramref> to skip is less than or equal to zero.
  401. /// </exception>
  402. public long Skip(long count)
  403. {
  404. if (count <= 0) {
  405. throw new ArgumentOutOfRangeException("count");
  406. }
  407. // v0.80 Skip by seeking if underlying stream supports it...
  408. if (baseInputStream.CanSeek) {
  409. baseInputStream.Seek(count, SeekOrigin.Current);
  410. return count;
  411. }
  412. else {
  413. int length = 2048;
  414. if (count < length) {
  415. length = (int) count;
  416. }
  417. byte[] tmp = new byte[length];
  418. int readCount = 1;
  419. long toSkip = count;
  420. while ((toSkip > 0) && (readCount > 0) ) {
  421. if (toSkip < length) {
  422. length = (int)toSkip;
  423. }
  424. readCount = baseInputStream.Read(tmp, 0, length);
  425. toSkip -= readCount;
  426. }
  427. return count - toSkip;
  428. }
  429. }
  430. /// <summary>
  431. /// Clear any cryptographic state.
  432. /// </summary>
  433. protected void StopDecrypting()
  434. {
  435. #if !NETCF_1_0
  436. inputBuffer.CryptoTransform = null;
  437. #endif
  438. }
  439. /// <summary>
  440. /// Returns 0 once the end of the stream (EOF) has been reached.
  441. /// Otherwise returns 1.
  442. /// </summary>
  443. public virtual int Available
  444. {
  445. get {
  446. return inf.IsFinished ? 0 : 1;
  447. }
  448. }
  449. /// <summary>
  450. /// Fills the buffer with more data to decompress.
  451. /// </summary>
  452. /// <exception cref="SharpZipBaseException">
  453. /// Stream ends early
  454. /// </exception>
  455. protected void Fill()
  456. {
  457. // Protect against redundant calls
  458. if (inputBuffer.Available <= 0) {
  459. inputBuffer.Fill();
  460. if (inputBuffer.Available <= 0) {
  461. throw new SharpZipBaseException("Unexpected EOF");
  462. }
  463. }
  464. inputBuffer.SetInflaterInput(inf);
  465. }
  466. #region Stream Overrides
  467. /// <summary>
  468. /// Gets a value indicating whether the current stream supports reading
  469. /// </summary>
  470. public override bool CanRead
  471. {
  472. get {
  473. return baseInputStream.CanRead;
  474. }
  475. }
  476. /// <summary>
  477. /// Gets a value of false indicating seeking is not supported for this stream.
  478. /// </summary>
  479. public override bool CanSeek {
  480. get {
  481. return false;
  482. }
  483. }
  484. /// <summary>
  485. /// Gets a value of false indicating that this stream is not writeable.
  486. /// </summary>
  487. public override bool CanWrite {
  488. get {
  489. return false;
  490. }
  491. }
  492. /// <summary>
  493. /// A value representing the length of the stream in bytes.
  494. /// </summary>
  495. public override long Length {
  496. get {
  497. return inputBuffer.RawLength;
  498. }
  499. }
  500. /// <summary>
  501. /// The current position within the stream.
  502. /// Throws a NotSupportedException when attempting to set the position
  503. /// </summary>
  504. /// <exception cref="NotSupportedException">Attempting to set the position</exception>
  505. public override long Position {
  506. get {
  507. return baseInputStream.Position;
  508. }
  509. set {
  510. throw new NotSupportedException("InflaterInputStream Position not supported");
  511. }
  512. }
  513. /// <summary>
  514. /// Flushes the baseInputStream
  515. /// </summary>
  516. public override void Flush()
  517. {
  518. baseInputStream.Flush();
  519. }
  520. /// <summary>
  521. /// Sets the position within the current stream
  522. /// Always throws a NotSupportedException
  523. /// </summary>
  524. /// <param name="offset">The relative offset to seek to.</param>
  525. /// <param name="origin">The <see cref="SeekOrigin"/> defining where to seek from.</param>
  526. /// <returns>The new position in the stream.</returns>
  527. /// <exception cref="NotSupportedException">Any access</exception>
  528. public override long Seek(long offset, SeekOrigin origin)
  529. {
  530. throw new NotSupportedException("Seek not supported");
  531. }
  532. /// <summary>
  533. /// Set the length of the current stream
  534. /// Always throws a NotSupportedException
  535. /// </summary>
  536. /// <param name="value">The new length value for the stream.</param>
  537. /// <exception cref="NotSupportedException">Any access</exception>
  538. public override void SetLength(long value)
  539. {
  540. throw new NotSupportedException("InflaterInputStream SetLength not supported");
  541. }
  542. /// <summary>
  543. /// Writes a sequence of bytes to stream and advances the current position
  544. /// This method always throws a NotSupportedException
  545. /// </summary>
  546. /// <param name="buffer">Thew buffer containing data to write.</param>
  547. /// <param name="offset">The offset of the first byte to write.</param>
  548. /// <param name="count">The number of bytes to write.</param>
  549. /// <exception cref="NotSupportedException">Any access</exception>
  550. public override void Write(byte[] buffer, int offset, int count)
  551. {
  552. throw new NotSupportedException("InflaterInputStream Write not supported");
  553. }
  554. /// <summary>
  555. /// Writes one byte to the current stream and advances the current position
  556. /// Always throws a NotSupportedException
  557. /// </summary>
  558. /// <param name="value">The byte to write.</param>
  559. /// <exception cref="NotSupportedException">Any access</exception>
  560. public override void WriteByte(byte value)
  561. {
  562. throw new NotSupportedException("InflaterInputStream WriteByte not supported");
  563. }
  564. /// <summary>
  565. /// Entry point to begin an asynchronous write. Always throws a NotSupportedException.
  566. /// </summary>
  567. /// <param name="buffer">The buffer to write data from</param>
  568. /// <param name="offset">Offset of first byte to write</param>
  569. /// <param name="count">The maximum number of bytes to write</param>
  570. /// <param name="callback">The method to be called when the asynchronous write operation is completed</param>
  571. /// <param name="state">A user-provided object that distinguishes this particular asynchronous write request from other requests</param>
  572. /// <returns>An <see cref="System.IAsyncResult">IAsyncResult</see> that references the asynchronous write</returns>
  573. /// <exception cref="NotSupportedException">Any access</exception>
  574. public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
  575. {
  576. throw new NotSupportedException("InflaterInputStream BeginWrite not supported");
  577. }
  578. /// <summary>
  579. /// Closes the input stream. When <see cref="IsStreamOwner"></see>
  580. /// is true the underlying stream is also closed.
  581. /// </summary>
  582. public override void Close()
  583. {
  584. if ( !isClosed ) {
  585. isClosed = true;
  586. if ( isStreamOwner ) {
  587. baseInputStream.Close();
  588. }
  589. }
  590. }
  591. /// <summary>
  592. /// Reads decompressed data into the provided buffer byte array
  593. /// </summary>
  594. /// <param name ="buffer">
  595. /// The array to read and decompress data into
  596. /// </param>
  597. /// <param name ="offset">
  598. /// The offset indicating where the data should be placed
  599. /// </param>
  600. /// <param name ="count">
  601. /// The number of bytes to decompress
  602. /// </param>
  603. /// <returns>The number of bytes read. Zero signals the end of stream</returns>
  604. /// <exception cref="SharpZipBaseException">
  605. /// Inflater needs a dictionary
  606. /// </exception>
  607. public override int Read(byte[] buffer, int offset, int count)
  608. {
  609. if (inf.IsNeedingDictionary)
  610. {
  611. throw new SharpZipBaseException("Need a dictionary");
  612. }
  613. int remainingBytes = count;
  614. while (true) {
  615. int bytesRead = inf.Inflate(buffer, offset, remainingBytes);
  616. offset += bytesRead;
  617. remainingBytes -= bytesRead;
  618. if (remainingBytes == 0 || inf.IsFinished) {
  619. break;
  620. }
  621. if ( inf.IsNeedingInput ) {
  622. Fill();
  623. }
  624. else if ( bytesRead == 0 ) {
  625. throw new ZipException("Dont know what to do");
  626. }
  627. }
  628. return count - remainingBytes;
  629. }
  630. #endregion
  631. #region Instance Fields
  632. /// <summary>
  633. /// Decompressor for this stream
  634. /// </summary>
  635. protected Inflater inf;
  636. /// <summary>
  637. /// <see cref="InflaterInputBuffer">Input buffer</see> for this stream.
  638. /// </summary>
  639. protected InflaterInputBuffer inputBuffer;
  640. /// <summary>
  641. /// Base stream the inflater reads from.
  642. /// </summary>
  643. private Stream baseInputStream;
  644. /// <summary>
  645. /// The compressed size
  646. /// </summary>
  647. protected long csize;
  648. /// <summary>
  649. /// Flag indicating wether this instance has been closed or not.
  650. /// </summary>
  651. bool isClosed;
  652. /// <summary>
  653. /// Flag indicating wether this instance is designated the stream owner.
  654. /// When closing if this flag is true the underlying stream is closed.
  655. /// </summary>
  656. bool isStreamOwner = true;
  657. #endregion
  658. }
  659. }