How to use the pouchdb-binary-utils.readAsBinaryString function in pouchdb-binary-utils

To help you get started, we’ve selected a few pouchdb-binary-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pouchdb / pouchdb / packages / node_modules / pouchdb-adapter-idb / src / utils.js View on Github external
function readBlobData(body, type, asBlob, callback) {
  if (asBlob) {
    if (!body) {
      callback(createBlob([''], {type: type}));
    } else if (typeof body !== 'string') { // we have blob support
      callback(body);
    } else { // no blob support
      callback(b64StringToBlob(body, type));
    }
  } else { // as base64 string
    if (!body) {
      callback('');
    } else if (typeof body !== 'string') { // we have blob support
      readAsBinaryString(body, function (binary) {
        callback(btoa(binary));
      });
    } else { // no blob support
      callback(body);
    }
  }
}
github pouchdb / pouchdb / packages / node_modules / pouchdb-adapter-indexeddb / src / getAttachment.js View on Github external
function parseAttachment(attachment, opts, cb) {
  if (opts.binary) {
    return cb(null, attachment);
  } else {
    readAsBinaryString(attachment, function (binString) {
      cb(null, btoa(binString));
    });
  }
}
github stockulus / pouchdb-react-native / packages / pouchdb-adapter-asyncstorage-pure / src / get_attachment.js View on Github external
db.storage.get(keys.forDocument(docId), (error, doc) => {
    if (error) {
      return callback(createError(
        MISSING_DOC, error.message || 'missing-read-error'))
    }

    const rev = opts.rev ? doc.revs[opts.rev].data : doc.data
    const digest = rev._attachments[attachId].digest

    if (opts.binary) {
      return callback(null, doc.attachments[digest].data)
    }

    readAsBinaryString(doc.attachments[digest].data, binString => {
      callback(null, btoa(binString))
    })
  })
}
github stockulus / pouchdb-react-native / packages / pouchdb-adapter-leveldb-core-rn / lib / index-browser.js View on Github external
function prepareAttachmentForStorage(attData, cb) {
  pouchdbBinaryUtils.readAsBinaryString(attData, cb);
}
github pouchdb / pouchdb / packages / node_modules / pouchdb-adapter-indexeddb / src / util.js View on Github external
return new Promise(function (resolve) {
    var data = src.attachments[doc._attachments[name].digest].data;
    readAsBinaryString(data, function (binString) {
      doc._attachments[name].data = btoa(binString);
      delete doc._attachments[name].length;
      resolve();
    });
  });
}