download link
#!/bin/env ruby
require 'stringio'
end_of_headers="\r\n\r\n"
outbuf=""
chunksize=-1
filename=ARGV[0]
f=File.new(filename,"r")
everything=f.gets(nil)
bodystart=everything.index(end_of_headers)
sio=StringIO.new(everything)
header=sio.read(bodystart + end_of_headers.length)
if header.match(/Transfer-Encoding: chunked/i)
until chunksize==0
chunksize=sio.gets("\r\n").rstrip.hex
outbuf+=sio.read(chunksize)
2.times {sio.getc}
end
else
warn("#{filename} doesn't have a Transfer-Encoding: chunked header")
exit(1)
end
print outbuf
No comments:
Post a Comment