azzlack / Microsoft.AspNet.WebApi.MessageHandlers.Compression

Drop-in module for ASP.Net WebAPI that enables GZip and Deflate support
Apache License 2.0
194 stars 54 forks source link

Unnecessary Byte Array Buffer in BaseCompressor.Compressor #41

Closed phil000 closed 7 years ago

phil000 commented 8 years ago

Hello, Looking at this Compress method in BaseCompressor it creates a byte array, reads from the memory stream into that byte array, creates another memory stream from this byte array, and finally copies that new stream into the ‘destination’ stream.

This all seems unnecessary.

Copying directly from the compressed stream (mem) into the destination and all the tests pass.

//1. NOTE REALLY REQUIRED:
//var compressed = new byte[mem.Length];
//await mem.ReadAsync(compressed, 0, compressed.Length);
//var outStream = new MemoryStream(compressed);
//await outStream.CopyToAsync(destination);

//2. OR JUST:
await mem.CopyToAsync(destination);