What are the best methods for reading and writing binary data in Ruby?
In the code example below, I needed to send the binary via HTTP (as POST data):
class SimpleHandler < Mongrel::HttpHandler
def process(request, response)
response.start(200) do |head,out|
head["Content-Type"] = "application/ocsp-responder"
f = File.new("resp.der", "r")
begin
while true
out.syswrite(f.sysread(1))
end
rescue EOFError => err
puts "Sent response."
end
end
end
end
Although this code seems to work well, it is probably not very idiomatic. How can I improve it?
source
share