@@ -440,7 +440,7 @@ public static async Task<bool> StringResponseAsync(
440440 var buffer = ( encoding ?? Encoding . UTF8 ) . GetBytes ( content ) ;
441441
442442 context . Response . ContentType = contentType ;
443- await context . Response . OutputStream . WriteAsync ( buffer , 0 , buffer . Length , cancellationToken ) ;
443+ await context . Response . OutputStream . WriteAsync ( buffer , 0 , buffer . Length , cancellationToken ) . ConfigureAwait ( false ) ;
444444
445445 return true ;
446446 }
@@ -512,8 +512,8 @@ public static async Task<MemoryStream> CompressAsync(
512512 {
513513 using ( var compressor = new DeflateStream ( targetStream , CompressionMode . Compress , true ) )
514514 {
515- await buffer . CopyToAsync ( compressor , 1024 , cancellationToken ) ;
516- await buffer . CopyToAsync ( compressor ) ;
515+ await buffer . CopyToAsync ( compressor , 1024 , cancellationToken ) . ConfigureAwait ( false ) ;
516+ await buffer . CopyToAsync ( compressor ) . ConfigureAwait ( false ) ;
517517
518518 // WebSocket use this
519519 targetStream . Write ( LastByte , 0 , 1 ) ;
@@ -524,7 +524,7 @@ public static async Task<MemoryStream> CompressAsync(
524524 {
525525 using ( var compressor = new DeflateStream ( buffer , CompressionMode . Decompress ) )
526526 {
527- await compressor . CopyToAsync ( targetStream ) ;
527+ await compressor . CopyToAsync ( targetStream ) . ConfigureAwait ( false ) ;
528528 }
529529 }
530530
@@ -534,63 +534,20 @@ public static async Task<MemoryStream> CompressAsync(
534534 {
535535 using ( var compressor = new GZipStream ( targetStream , CompressionMode . Compress , true ) )
536536 {
537- await buffer . CopyToAsync ( compressor ) ;
537+ await buffer . CopyToAsync ( compressor ) . ConfigureAwait ( false ) ;
538538 }
539539 }
540540 else
541541 {
542542 using ( var compressor = new GZipStream ( buffer , CompressionMode . Decompress ) )
543543 {
544- await compressor . CopyToAsync ( targetStream ) ;
544+ await compressor . CopyToAsync ( targetStream ) . ConfigureAwait ( false ) ;
545545 }
546546 }
547547
548548 break ;
549549 case CompressionMethod . None :
550- await buffer . CopyToAsync ( targetStream ) ;
551- break ;
552- default :
553- throw new ArgumentOutOfRangeException ( nameof ( method ) , method , null ) ;
554- }
555-
556- return targetStream ;
557- }
558-
559- /// <summary>
560- /// Compresses the specified buffer stream using the G-Zip compression algorithm.
561- /// </summary>
562- /// <param name="buffer">The buffer.</param>
563- /// <param name="method">The method.</param>
564- /// <returns>
565- /// A block of bytes of compressed stream.
566- /// </returns>
567- public static MemoryStream Compress (
568- this Stream buffer ,
569- CompressionMethod method = CompressionMethod . Gzip )
570- {
571- buffer . Position = 0 ;
572- var targetStream = new MemoryStream ( ) ;
573-
574- switch ( method )
575- {
576- case CompressionMethod . Deflate :
577- using ( var compressor = new DeflateStream ( targetStream , CompressionMode . Compress , true ) )
578- {
579- buffer . CopyTo ( compressor , 1024 ) ;
580- buffer . CopyTo ( compressor ) ;
581-
582- // WebSocket use this
583- targetStream . Write ( LastByte , 0 , 1 ) ;
584- targetStream . Position = 0 ;
585- }
586-
587- break ;
588- case CompressionMethod . Gzip :
589- using ( var compressor = new GZipStream ( targetStream , CompressionMode . Compress , true ) )
590- {
591- buffer . CopyTo ( compressor ) ;
592- }
593-
550+ await buffer . CopyToAsync ( targetStream ) . ConfigureAwait ( false ) ;
594551 break ;
595552 default :
596553 throw new ArgumentOutOfRangeException ( nameof ( method ) , method , null ) ;
0 commit comments