Created
June 25, 2015 05:00
-
-
Save yyuu/740942582c6c624bd3d0 to your computer and use it in GitHub Desktop.
json2msgpackgz.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "json" | |
require "msgpack" | |
require "tempfile" | |
require "zlib" | |
io = Tempfile.new(File.basename($0)) | |
gzip = Zlib::GzipWriter.new(io) | |
packer = MessagePack::Packer.new(gzip) | |
ARGF.each do |s| | |
record = JSON.parse(s) | |
packer.pack(record) | |
end | |
packer.flush() | |
gzip.finish() | |
io.rewind() | |
STDOUT.write(io.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment