/// <summary>
        /// Writes data from accessor.
        /// </summary>
        public static void Write(this IBinaryAccessor accessor, IBinaryAccessor source, long count, int bufferSize = 0x1000, bool throwIfOutOfBound = false)
        {
            if (accessor == null)
            {
                throw new ArgumentNullException("accessor");
            }

            if (source == null)
            {
                throw new ArgumentNullException("sourceBinaryAccessor");
            }

            byte[] buffer = new byte[bufferSize];

            while (count > 0)
            {
                int copySize  = (int)(count > bufferSize ? bufferSize : count);
                int readCount = source.Read(buffer, 0, copySize);

                if (copySize != readCount)
                {
                    if (throwIfOutOfBound)
                    {
                        throw new IOException(SR.BlobReadOutOfBound);
                    }
                }

                accessor.Write(buffer, 0, readCount);

                count -= copySize;
            }
        }
        /// <summary>
        /// Compare two accessors.
        /// </summary>
        /// <param name="accessor1">The accessor1.</param>
        /// <param name="accessor2">The accessor2.</param>
        /// <param name="bufferSize">The size of buffer.</param>
        /// <param name="posOfFirstDiffByte">Position of the first diff byte or -1 if files are equal.</param>
        /// <returns>Return true indicates that the contents of the files are the same. Return false if the files are different.</returns>
        public static bool CompareTo(this IBinaryAccessor accessor1, IBinaryAccessor accessor2, int bufferSize, out long posOfFirstDiffByte)
        {
            if (bufferSize < 0)
            {
                throw new ArgumentOutOfRangeException("bufferSize");
            }

            posOfFirstDiffByte = -1;

            // If some of the files does not exists then assume they are different.
            if (accessor1 == null || accessor2 == null)
            {
                return(false);
            }

            int position = 0;

            byte[] buffer1 = new byte[bufferSize];
            byte[] buffer2 = new byte[bufferSize];

            while (true)
            {
                int readCount1 = accessor1.Read(buffer1, 0, bufferSize);
                int readCount2 = accessor2.Read(buffer2, 0, bufferSize);

                int minReadCount = Math.Min(readCount1, readCount2);
                for (int i = 0; i < minReadCount; i++)
                {
                    if (buffer1[i] != buffer2[i])
                    {
                        posOfFirstDiffByte = position;
                        return(false);
                    }

                    position++;
                }

                if (readCount1 != readCount2)
                {
                    posOfFirstDiffByte = position;
                    return(false);
                }

                if (readCount1 < bufferSize)
                {
                    break;
                }
            }

            return(true);
        }
        public static byte[] ReadBytes(this IBinaryAccessor accessor, int count)
        {
            if (accessor == null)
            {
                throw new ArgumentNullException("accessor");
            }

            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            byte[] buffer    = new byte[count];
            int    readCount = accessor.Read(buffer, 0, count);

            if (readCount != count)
            {
                throw new IOException(SR.StreamReadOutOfBound);
            }

            return(buffer);
        }