Exemple #1
0
        /// <summary>
        /// Writes the stream into another DataStream.
        /// </summary>
        /// <param name="stream">Output DataStream.</param>
        public void WriteTo(DataStream stream)
        {
            if (Disposed)
            {
                throw new ObjectDisposedException(nameof(DataStream));
            }

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (stream.Disposed)
            {
                throw new ObjectDisposedException(nameof(stream));
            }

            long currPos = Position;

            Seek(0, SeekMode.Start);

            const int BufferSize = 70 * 1024;

            byte[] buffer = new byte[Length > BufferSize ? BufferSize : Length];

            while (!EndOfStream)
            {
                int read = BlockRead(this, buffer);
                stream.Write(buffer, 0, read);
            }

            Seek(currPos, SeekMode.Start);
        }
Exemple #2
0
        /// <summary>
        /// Writes the stream into another DataStream.
        /// </summary>
        /// <param name="stream">Output DataStream.</param>
        public void WriteTo(DataStream stream)
        {
            if (Disposed)
            {
                throw new ObjectDisposedException(nameof(DataStream));
            }

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (stream.Disposed)
            {
                throw new ObjectDisposedException(nameof(stream));
            }

            long currPos = Position;

            Seek(0, SeekMode.Start);

            const int BufferSize = 5 * 1024;

            byte[] buffer = new byte[BufferSize];

            int written     = 0;
            int bytesToRead = 0;

            do
            {
                if (written + BufferSize > Length)
                {
                    bytesToRead = (int)(Length - written);
                }
                else
                {
                    bytesToRead = BufferSize;
                }

                written += Read(buffer, 0, bytesToRead);
                stream.Write(buffer, 0, bytesToRead);
            } while (written != Length);

            Seek(currPos, SeekMode.Start);
        }