C# Stream 轉 Bytes
#region - Stream 轉 Bytes -
/// <summary>
/// Stream 轉 Bytes
/// </summary>
/// <param name="stream"> Stream</param>
/// <returns> Bytes</returns>
public static byte[] StreamToBytes( Stream stream)
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
stream.Seek(0, SeekOrigin.Begin);
return bytes;
}
#endregion
#region - Bytes 轉 Stream -
/// <summary>
/// Bytes 轉 Stream
/// </summary>
/// <param name="bytes"> Bytes</param>
/// <returns> Stream</returns>
public static Stream BytesToStream( byte[] bytes)
{
return new MemoryStream(bytes);
}
#endregion
留言
張貼留言