I usually use Open3.popen3 in my Ruby CGI scripts to start a Linux command, parse its standard output and converting the bytes to the chunked transfer encoding ( https://en.wikipedia.org/wiki/Chunked_transfer_encoding )
th<<Thread.new do
counter=0
while data=stdout.read(64*1024)
STDOUT.puts "#{data.size.to_s(16)};"
STDOUT.print data
STDOUT.puts
counter+=data.size
end
STDOUT.puts "0"
STDOUT.puts "Content-Length: #{counter}"
STDOUT.puts
end
th.join
I wonder if maybe already is there a Linux command line utility / filter which do this particular job: counting the bytes, printing the chunks with the proper headers, and the closing footer with the counted content length. So I simply could pipe the command output to that filter, no need for Open3.popen3, I think conversion would be faster.