diff --git a/KaitaiStream.cs b/KaitaiStream.cs index c1d6b22..d7464ef 100644 --- a/KaitaiStream.cs +++ b/KaitaiStream.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; -using System.Linq; using System.Globalization; namespace Kaitai @@ -615,7 +614,8 @@ namespace Kaitai { using (MemoryStream target = new MemoryStream()) { - ds.CopyTo(target); + byte[] buffer = new byte[32768]; + CopyTo(target, ds); return target.ToArray(); } } @@ -708,5 +708,24 @@ namespace Kaitai } #endregion + + #region Compatibility methods + + /// + /// Replaces Stream.CopyTo from System.Linq for backwards compatibility. + /// + /// Stream to copy data from. + /// Stream to copy data to. + private static void CopyTo(Stream source, Stream destination) + { + byte[] buffer = new byte[32768]; + int read; + while ((read = source.Read(buffer, 0, buffer.Length)) > 0) + { + destination.Write(buffer, 0, read); + } + } + + #endregion } }