File: chunked_bzip2.py

package info (click to toggle)
elinks 0.12~pre5-9
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 19,604 kB
  • sloc: ansic: 99,308; sh: 5,293; python: 3,878; perl: 2,175; makefile: 1,131; pascal: 924; yacc: 295; lisp: 125; ruby: 70; awk: 65
file content (16 lines) | stat: -rwxr-xr-x 552 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env python
import bz2, os, time

data1 = '<html><body>Two lines should be visible.<br/>The second line.</body></html>'
cd1 = bz2.compress(data1)

length = len(cd1)
next_chunk = hex(length - 10)[2:]

os.write(1, "Date: Sun, 20 Jan 2008 15:24:00 GMT\r\nServer: ddd\r\nTransfer-Encoding: chunked\r\nContent-Encoding: bzip2\r\nConnection: close\r\nContent-Type: text/html; charset=ISO-8859-1\r\n")
os.write(1, "\r\na\r\n")
os.write(1, cd1[:10])
time.sleep(2)
os.write(1, "\r\n%s\r\n" % next_chunk)
os.write(1, cd1[10:])
os.write(1, "\r\n0\r\n")