Ejemplo n.º 1
0
        /// <summary>
        /// 从流中读入一个缓冲数组
        /// </summary>
        /// <param name="stream">要读取的流</param>
        /// <param name="length">读取的字节长度</param>
        /// <param name="cancellationToken">取消操作的TOKEN</param>
        /// <returns>缓冲数组</returns>
        public static async Task <byte[]> ReadBufferAsync(this Stream stream, int length, CancellationToken?cancellationToken = null)
        {
            var(buffer, _) = await stream.ReadBufferAsync(length, true, cancellationToken);

            return(buffer);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 从流中读入一个 <see cref="T:System.Int64"/>
 /// </summary>
 /// <param name="stream">要读取的流</param>
 /// <param name="cancellationToken">取消操作的TOKEN</param>
 /// <returns>读取的 <see cref="T:System.Int64"/></returns>
 public static async Task <long> ReadInt64Async(this Stream stream, CancellationToken?cancellationToken = null)
 {
     return(BitConverter.ToInt64(await stream.ReadBufferAsync(8, cancellationToken), 0));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 从流中读入一个 <see cref="T:System.Int64"/>
 /// </summary>
 /// <param name="stream">要读取的流</param>
 /// <param name="cancellationToken">取消操作的TOKEN</param>
 /// <returns>读取的 <see cref="T:System.Int64"/></returns>
 public static async Task <double> ReadDoubleAsync(this Stream stream, CancellationToken?cancellationToken = null)
 {
     return(BitConverter.ToDouble(await stream.ReadBufferAsync(sizeof(double), cancellationToken), 0));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 从流中读入一个 <see cref="T:System.Int32"/>
 /// </summary>
 /// <param name="stream">要读取的流</param>
 /// <param name="cancellationToken">取消操作的TOKEN</param>
 /// <returns>读取的 <see cref="T:System.Int32"/></returns>
 public static async Task <uint> ReadUInt32Async(this Stream stream, CancellationToken?cancellationToken = null)
 {
     return(BitConverter.ToUInt32(await stream.ReadBufferAsync(4, cancellationToken), 0));
 }