Skip to content

Instantly share code, notes, and snippets.

@yyuu
Created June 25, 2015 05:00
Show Gist options
  • Save yyuu/740942582c6c624bd3d0 to your computer and use it in GitHub Desktop.
Save yyuu/740942582c6c624bd3d0 to your computer and use it in GitHub Desktop.
json2msgpackgz.rb
#!/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