File: download.cgi

package info (click to toggle)
ruby-httpclient 2.8.3%2Bgit20211122.4658227-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,908 kB
  • sloc: ruby: 9,963; makefile: 10; sh: 2
file content (23 lines) | stat: -rwxr-xr-x 492 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/local/bin/ruby

print "Content-Type: application/octet-stream\r\n"
print "Transfer-Encoding: chunked\r\n"
print "\r\n"

def dump_chunk_size(size)
  sprintf("%x", size) + "\r\n"
end

def dump_chunk(str)
  dump_chunk_size(str.size) + str + "\r\n"
end

buf_size = 1024 * 16
STDOUT.sync = true
File.open(File.expand_path('10M.bin', File.dirname(__FILE__))) do |file|
  buf = ''
  while !file.read(buf_size, buf).nil?
    print dump_chunk(buf)
  end
  print dump_chunk_size(0) + "\r\n"
end