Owin.Compression icon indicating copy to clipboard operation
Owin.Compression copied to clipboard

Assuming files are always UTF-8 encoded text

Open apdevelop opened this issue 1 year ago • 2 comments

Reading file contents in getFile() function of OwinCompression module implemented as StreamReader.ReadToEndAsync() + System.Text.Encoding.UTF8.GetBytes: https://github.com/Thorium/Owin.Compression/blob/master/src/Owin.Compression/CompressionModule.fs#L156

How it will proceed with arbitrary encoded text files or binary files (for example, images and fonts) - the file contents will be corrupted in response. This applies when using .MapCompressionModule(...) and respectively ResponseMode.File.

apdevelop avatar Feb 16 '23 13:02 apdevelop

Good question, I've not had issues with it but then again I'm skipping most of the binary files with file extension types because binary images and binary fonts etc. are already compressed / doesn't benefit of zip so much.

And I guess the potential issue applies only cases where the file is directly read from disk, not cases where this is used in pipeline with selfhost or other file server?

Is this actual issue, and if it is, do you have any ideas for improvement?

Thorium avatar Feb 16 '23 21:02 Thorium

And I guess the potential issue applies only cases where the file is directly read from disk

Yes, it applies to the .MapCompressionModule() -> getFile() call chain. I can agree that compressed binary files are not intended for additional compression, but DefaultCompressionSettings.AllowedExtensionAndMimeTypes for example, contains .ttf and .eot extensions which are binary files, if I remember correctly.

It can be improved by reading file in binary mode as byte array at once, like FileStream.ReadAsync (taking into account some performance issues).

apdevelop avatar Feb 17 '23 07:02 apdevelop