def load(fname, opts={})

      # check before loading anything

      ids_to_load = []

      readlines(fname) do |line, i|

        doc = begin
          Rufus::Json.decode(line)
        rescue Rufus::Json::ParserError => pe
          raise ArgumentError.new(
            "dump file corrupted, line #{i}, not [valid] json: #{line}")
        end

        fail ArgumentError.new(
          "dump file corrupted, line #{i}, not a hash: #{line}"
        ) if doc.class != Hash

        check_attachments(doc) # will fail if there is a 'stub' attachment

        ids_to_load << doc['_id']
      end

      # clean db if :overwrite => true

      if opts[:overwrite]
        delete('.')
        put('.')
      end

      # complain if there is already a doc with the same id as one of the docs
      # we are about to load

      in_common = ids & ids_to_load

      fail ArgumentError.new(
        "dump file contains already present ids : #{in_common.inspect}"
      ) if in_common.any?

      # load

      readlines(fname) do |line, i|

        doc = Rufus::Json.decode(line)
        check_attachments(doc) # to remove the 'revpos'

        put(doc)
      end
    end
def load(fname, opts={})

      # check before loading anything

      ids_to_load = []

      readlines(fname) do |line, i|

        doc = begin
          Rufus::Json.decode(line)
        rescue Rufus::Json::ParserError => pe
          raise ArgumentError.new(
            "dump file corrupted, line #{i}, not [valid] json: #{line}")
        end

        fail ArgumentError.new(
          "dump file corrupted, line #{i}, not a hash: #{line}"
        ) if doc.class != Hash

        check_attachments(doc) # will fail if there is a 'stub' attachment

        ids_to_load << doc['_id']
      end

      # clean db if :overwrite => true

      if opts[:overwrite]
        delete('.')
        put('.')
      end

      # complain if there is already a doc with the same id as one of the docs
      # we are about to load

      in_common = ids & ids_to_load

      fail ArgumentError.new(
        "dump file contains already present ids : #{in_common.inspect}"
      ) if in_common.any?

      # load

      readlines(fname) do |line, i|

        doc = Rufus::Json.decode(line)
        check_attachments(doc) # to remove the 'revpos'

        put(doc)
      end
    end
Given a file produced by #dump, will load it into this database.

 If the :overwrite option is set to true, the database will be cleaned
 before the load operation.

 It will fail with an ArgumentError if the dump file is corrupted.
 It will fail as well if dump file contains an doc with an id aleady
 present.

 It fails before loading anything (or overwriting anything).