#!/usr/bin/env python
# -*- coding: utf-8 -*-

import gzip

# 读取
with gzip.open('somefile.gz', 'r') as f:
    text = f.read()
# 写入
with gzip.open('somefile.gz', 'w') as f:
    f.write(text)
# 压缩
with gzip.open('somefile.gz', 'w', compresslevel=5) as f:
    f.write(text)

import bz2

with bz2.open('somefile.bz2', 'r') as f:
    text2 = f.read()

2c5631b731cddbef9a323a4b54caa8bbbfd457ae
<mask token>

<mask token>
with gzip.open('somefile.gz', 'r') as f:
    text = f.read()
with gzip.open('somefile.gz', 'w') as f:
    f.write(text)
with gzip.open('somefile.gz', 'w', compresslevel=5) as f:
    f.write(text)
<mask token>
with bz2.open('somefile.bz2', 'r') as f:
    text2 = f.read()

import gzip
with gzip.open('somefile.gz', 'r') as f:
    text = f.read()
with gzip.open('somefile.gz', 'w') as f:
    f.write(text)
with gzip.open('somefile.gz', 'w', compresslevel=5) as f:
    f.write(text)
import bz2
with bz2.open('somefile.bz2', 'r') as f:
    text2 = f.read()

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import gzip

# 读取
with gzip.open('somefile.gz', 'r') as f:
    text = f.read()
# 写入
with gzip.open('somefile.gz', 'w') as f:
    f.write(text)
# 压缩
with gzip.open('somefile.gz', 'w', compresslevel=5) as f:
    f.write(text)

import bz2

with bz2.open('somefile.bz2', 'r') as f:
    text2 = f.read()
