sh
sudo yum install python-pip -y
sudo pip install msgpack-python msgpack-tool
test.csv: Space separated CSV file test.pack: Create a pack created as a floating point type
packer.py
import csv
import msgpack
infile = csv.reader(open('test.csv', 'rb'), delimiter=' ')
outfile = open('test.pack','w')
packer = msgpack.Packer()
for row in infile:
outfile.write(packer.pack(map(float,row)))
Try piped with standard input and unpack the contents of the pack file
zcat test.pack.gz | unpacker.py
unpacker.py
import sys
import msgpack
BUF_SIZE = 64*1024
unpacker = msgpack.Unpacker()
while True:
buf = sys.stdin.read(BUF_SIZE)
if not buf:
break
unpacker.feed(buf)
for obj in unpacker:
print( obj )
Recommended Posts