socketry / async-http

MIT License
298 stars 45 forks source link

Open File in binary mode in HTTP::Body::File #13

Closed janko closed 5 years ago

janko commented 5 years ago

It's generally safer to open the file in binary mode, because then C won't try to do any conversions between representations of newlines depending on the OS, it will just retrieve bytes as is. See Avdi's RubyTapas for more details: https://www.rubytapas.com/2016/12/14/ruby-code-on-windows/

ioquatix commented 5 years ago

Haha, this is a great idea. Doh :p

ioquatix commented 5 years ago

Haha, this is a great idea. Doh :p

ioquatix commented 5 years ago

I am going to add a spec for this too.

janko commented 5 years ago

@ioquatix I tried, but I wasn't sure how. I thought that when a file is opened in UTF-8 mode, that #read will return the data in UTF-8 encoding and we can test against that. #read without argument has that behaviour, but it seems that with the length argument the data is always returned in binary encoding, regardless of whether the file has been opened in binary mode.