Identify binary files in plainblob.
Wed Dec 21 15:00:33 UTC 2005 Alberto Bertogli <albertogli@telpin.com.ar>
* Identify binary files in plainblob.
If we want to do a plainblob of a binary file, it's better to offer a proper
download than to display it as text/plain.
This patch identifies binary files (looking at darcs' information) and offers
them for download with the proper name.
{
hunk ./darcsweb.cgi 398
+def print_binary_header(fname = None):
+ print "Content-type: application/octet-stream"
+ if fname:
+ print "Content-Disposition:attachment;filename=%s" % fname
+ print
hunk ./darcsweb.cgi 1681
- print_plain_header()
hunk ./darcsweb.cgi 1682
- for l in f:
- sys.stdout.write(fixu8(l))
+
+ if isbinary(fname):
+ print_binary_header(os.path.basename(fname))
+ for l in f:
+ sys.stdout.write(l)
+ else:
+ print_plain_header()
+ for l in f:
+ sys.stdout.write(fixu8(l))
}