%20bit%20Compression&f=false
from bitarray import bitarray
from gzip import GzipFile
from cStringIO import StringIO
import marshal
bc=bitarray()
for n in xrange( 1000 ) :
bc.extend(bitarray(10**6))
#120M
f1=open('/tmp/bc1.ba','wa')
bc.tofile(f1)
sio = StringIO()
f2=open('/tmp/bc2.ba','wb')
w = GzipFile(None,'wb',9,sio)
w.write(bc.tostring())
w.close()
marshal.dump(f2,sio)
# 一般在 160k 左右
w = GzipFile('/tmp/bc3.ba','wb',9)
w.write(bc.tostring())
w.close()
r = GzipFile('/tmp/bc.ba','rb',9)
rr = r.read()
bb = bitarray()
bb.fromstring(rr)
bb == bc
|
阅读(1068) | 评论(0) | 转发(0) |