# File lib/aws/s3/object_collection.rb, line 140
      def delete *objects

        # Detect and retrieve options from the end of the splat.
        if
          objects.size == 2 and
          objects[0].is_a?(Array) and
          objects[1].is_a?(Hash)
        then
          client_opts = objects.pop
        else
          client_opts = {}
        end

        objects = objects.flatten.collect do |obj|
          case obj
          when String        then { :key => obj }
          when Hash          then obj
          when S3Object      then { :key => obj.key }
          when ObjectVersion then { :key => obj.key, :version_id => obj.version_id }
          else
            msg = "objects must be keys (strings or hashes with :key and " +
                  ":version_id), S3Objects or ObjectVersions, got " +
                  object.class.name
            raise ArgumentError, msg
          end
        end

        batch_helper = BatchHelper.new(1000) do |batch|
          client_opts[:bucket_name] = bucket.name
          client_opts[:quiet] = true
          client_opts[:objects] = batch
          client.delete_objects(client_opts)
        end

        error_counts = {}
        batch_helper.after_batch do |response|
          response.errors.each do |error|
            error_counts[error.code] ||= 0
            error_counts[error.code] += 1
          end
        end

        objects.each do |object|
          batch_helper.add(object)
        end

        batch_helper.complete!

        raise Errors::BatchDeleteError.new(error_counts) unless
          error_counts.empty?

        nil

      end