| 12345678910111213141516171819202122232425262728293031323334 |
- using System.IO;
- namespace Masuit.Tools
- {
- public static class StreamExtensions
- {
- /// <summary>
- /// 将流转换为内存流
- /// </summary>
- /// <param name="stream"></param>
- /// <returns></returns>
- public static MemoryStream SaveAsMemoryStream(this Stream stream)
- {
- stream.Position = 0;
- return new MemoryStream(stream.ToArray());
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="stream"></param>
- /// <returns></returns>
- public static byte[] ToArray(this Stream stream)
- {
- stream.Position = 0;
- byte[] bytes = new byte[stream.Length];
- stream.Read(bytes, 0, bytes.Length);
- // 设置当前流的位置为流的开始
- stream.Seek(0, SeekOrigin.Begin);
- return bytes;
- }
- }
- }
|