mongo-ruby-driver/bin/validate

20 lines
651 B
Plaintext
Raw Normal View History

#!/usr/bin/env ruby
#
2009-01-09 22:30:04 +00:00
# usage: validate somefile.xson somefile.bson
#
# Reads somefile.xson file (XML that describes a Mongo-type document),
# converts it into a Ruby OrderedHash, runs that through the BSON
# serialization code, and writes the BSON bytes to somefile.bson.
#
# This script is used by the mongo-qa project
# (http://github.com/mongodb/mongo-qa).
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
require 'mongo/util/xml_to_ruby'
2009-01-09 22:30:04 +00:00
obj = nil
File.open(ARGV[0], 'r') { |f| obj = XMLToRuby.new.xml_to_ruby(f) }
bson = BSON.new.serialize(obj).to_a
2009-01-09 22:30:04 +00:00
File.open(ARGV[1], 'wb') { |f| bson.each { |b| f.putc(b) } }