code: function fetch(filename) {
          var att = atts[filename];
          var path = encodeDocId(doc._id) + '/' + encodeAttachmentId(filename) +
            '?rev=' + doc._rev;
          return ajaxPromise(opts, {
            method: 'GET',
            url: genDBUrl(host, path),
            binary: true
          }).then(function (blob) {
            if (opts.binary) {
              return blob;
            }
            return new Promise(function (resolve) {
              pouchdbBinaryUtils.blobOrBufferToBase64(blob, resolve);
            });
          }).then(function (data) {
            delete att.stub;
            delete att.length;
            att.data = data;
          });
        }
docs: we fetch these manually in separate XHRs, because Sync Gateway would normally send it back as multipart/mixed, which we cannot parse. Also, this is more efficient than receiving attachments as base64-encoded strings.