Sha256: 5ace49661a6f7298aef1d7e32d9e254b73668a9cdf038e11ae2bacffd6c9e9ac

Contents?: true

Size: 1017 Bytes

Versions: 14

Compression:

Stored size: 1017 Bytes

Contents

#!/usr/bin/env ruby
# encoding: UTF-8

require 'rubygems'
require 'bson'

# Note that this will not properly round-trip in all cases
# from the output generated by j2bson.
begin
require 'yajl'
rescue LoadError
  puts "This script requires yajl. Please install as follows:"
  puts "  gem install yajl-ruby" 
  Process.exit
end

# Convert all documents in an IO into JSON.
def print_b2json(io)
  while not io.eof? do
    bsonobj = BSON.read_bson_document(io)
    Yajl::Encoder.encode(bsonobj, STDOUT)
    STDOUT << "\n"
  end
end

# print usage
def usage()
    STDERR << <<END_OF_USAGE
usage:  b2json [-h] [file1 [file2]]

   Converts a BSON file to JSON on STDOUT.
   You can pass multiple filenames.
   If no filenames are passed, then STDIN is consumed.

END_OF_USAGE
    exit
end

# no arg, use STDIN
# -h, print usage and exit
# otherwise loop of filenames
if ARGV.empty? then
    print_b2json(STDIN)
    exit
elsif ARGV[0] == "-h" then
    usage()
else
    ARGV.each { |fname| print_b2json(File.new(fname)) }
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
bson-1.8.6 bin/b2json
bson-1.8.6-java bin/b2json
bson-1.8.5-java bin/b2json
bson-1.8.5 bin/b2json
bson-1.8.4 bin/b2json
bson-1.8.4-java bin/b2json
bson-1.8.4.rc0-java bin/b2json
bson-1.8.4.rc0 bin/b2json
bson-1.8.3-java bin/b2json
bson-1.8.3 bin/b2json
bson-1.8.3.rc1-java bin/b2json
bson-1.8.3.rc1 bin/b2json
bson-1.8.3.rc0-java bin/b2json
bson-1.8.3.rc0 bin/b2json