Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bz2
- import mmap
- lines = '''This is my first line
- This is the second
- And the third
- '''
- with open("bz2TestFile", "wb") as f:
- f.write(bz2.compress(lines))
- with open("bz2TestFile", "rb") as f:
- mapped = mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ)
- print "Part of MMAPPED"
- # This does not work until I hit a minimum length
- # due to (I believe) the checksums in the bz2 algorithm
- #
- for x in range(len(mapped)+2):
- line = mapped[0:x]
- try:
- print x
- print bz2.decompress(line)
- except:
- pass
- # I can decompress the entire mmapped file
- print ":entire mmap file:"
- print bz2.decompress(mapped)
- # I can create a bz2File object from the file path
- # Is there a way to map the mmap object to this function?
- print ":BZ2 File readline:"
- bzF = bz2.BZ2File("bz2TestFile")
- # Seek to specific offset
- bzF.seek(22)
- # Read the data
- print bzF.readline()
Add Comment
Please, Sign In to add comment