def parse_db(stream)
      case stream.gets.to_i
      when DB_FORMAT
        @meta   = Oj.load(stream.gets)
        @tables = Oj.load(stream.gets)
        return true
      when 3..4
        # Old format, so read the directories segment then rebuild
        add_paths(Oj.load(stream.gets))
        return false
      when 0..2
        # Old format (pre-json), so read the directories segment then rebuild
        len = stream.gets.to_i
        add_paths(Marshal.load(stream.read(len)))
        return false
      else
        raise UnknownDBFormatError
      end
    rescue Oj::ParseError
      stream.rewind
      raise unless stream.gets.to_i == DB_FORMAT
      # try reading as formated json, which is much slower, but it is sometimes
      # useful to be able to directly read your db
      objects = []
      Oj.load(stream) { |obj| objects << obj }
      @meta, @tables = objects
      return true
    end
def parse_db(stream)
      case stream.gets.to_i
      when DB_FORMAT
        @meta   = Oj.load(stream.gets)
        @tables = Oj.load(stream.gets)
        return true
      when 3..4
        # Old format, so read the directories segment then rebuild
        add_paths(Oj.load(stream.gets))
        return false
      when 0..2
        # Old format (pre-json), so read the directories segment then rebuild
        len = stream.gets.to_i
        add_paths(Marshal.load(stream.read(len)))
        return false
      else
        raise UnknownDBFormatError
      end
    rescue Oj::ParseError
      stream.rewind
      raise unless stream.gets.to_i == DB_FORMAT
      # try reading as formated json, which is much slower, but it is sometimes
      # useful to be able to directly read your db
      objects = []
      Oj.load(stream) { |obj| objects << obj }
      @meta, @tables = objects
      return true
    end
returns true iff the database is in the most recent format