流操作

 #region -- 流操作

        /// <summary>
        /// 复制流
        /// </summary>
        public static MemoryStream CopyStream(Stream stream)
        {
            MemoryStream mstream = new MemoryStream();
            CopyStream(stream, mstream);
            return mstream;
        }

        /// <summary>
        /// 复制流
        /// </summary>
        public static void CopyStream(Stream source, Stream target)
        {
            byte[] bytes = new byte[1024];//临时字节数据数组
            if (source.CanRead)
            {
                while (true)
                {
                    int length = source.Read(bytes, 0, bytes.Length);
                    target.Write(bytes, 0, length);
                    if (length < bytes.Length)
                    {
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Stream转字节数组
        /// </summary>
        /// <returns></returns>
        public static byte[] ReadStream(Stream stream)
        {
            using (MemoryStream mstream = new MemoryStream())
            {
                CopyStream(stream, mstream);
                return mstream.ToArray();
            }
        }
        #endregion