@@ -1223,26 +1223,26 @@ private unsafe bool TryUncompressZlibData(ReadOnlySpan<byte> compressedData, out
12231223 fixed ( byte * compressedDataBase = compressedData )
12241224 {
12251225 using ( IMemoryOwner < byte > destBuffer = this . memoryAllocator . Allocate < byte > ( this . Configuration . StreamProcessingBufferSize ) )
1226- using ( var memoryStream = new UnmanagedMemoryStream ( compressedDataBase , compressedData . Length ) )
1227- using ( var bufferedStream = new BufferedReadStream ( this . Configuration , memoryStream ) )
1226+ using ( var memoryStreamOutput = new MemoryStream ( compressedData . Length ) )
1227+ using ( var memoryStreamInput = new UnmanagedMemoryStream ( compressedDataBase , compressedData . Length ) )
1228+ using ( var bufferedStream = new BufferedReadStream ( this . Configuration , memoryStreamInput ) )
12281229 using ( var inflateStream = new ZlibInflateStream ( bufferedStream ) )
12291230 {
1230- Span < byte > dest = destBuffer . GetSpan ( ) ;
1231+ Span < byte > destUncompressedData = destBuffer . GetSpan ( ) ;
12311232 if ( ! inflateStream . AllocateNewBytes ( compressedData . Length , false ) )
12321233 {
12331234 uncompressedBytesArray = Array . Empty < byte > ( ) ;
12341235 return false ;
12351236 }
12361237
1237- var uncompressedBytes = new List < byte > ( compressedData . Length ) ;
1238- int bytesRead = inflateStream . CompressedStream . Read ( dest , 0 , dest . Length ) ;
1238+ int bytesRead = inflateStream . CompressedStream . Read ( destUncompressedData , 0 , destUncompressedData . Length ) ;
12391239 while ( bytesRead != 0 )
12401240 {
1241- uncompressedBytes . AddRange ( dest . Slice ( 0 , bytesRead ) . ToArray ( ) ) ;
1242- bytesRead = inflateStream . CompressedStream . Read ( dest , 0 , dest . Length ) ;
1241+ memoryStreamOutput . Write ( destUncompressedData . Slice ( 0 , bytesRead ) ) ;
1242+ bytesRead = inflateStream . CompressedStream . Read ( destUncompressedData , 0 , destUncompressedData . Length ) ;
12431243 }
12441244
1245- uncompressedBytesArray = uncompressedBytes . ToArray ( ) ;
1245+ uncompressedBytesArray = memoryStreamOutput . ToArray ( ) ;
12461246 return true ;
12471247 }
12481248 }
0 commit comments