Skip to content

Commit

Permalink
(pouchdb#7862) - response.buffer() and blob.type have no/limited acce…
Browse files Browse the repository at this point in the history
…ss in ReactNative

response.buffer() is not supported at all, and blob.type is readonly in
ReactNative. Change the limited node/browser detection to (hopefully)
future-proof feature detection instead.

Errors fixed in RN:

    Creating blobs from 'ArrayBuffer' and 'ArrayBufferView' are not
    supported

    Cannot set property type of #<Blob> which has only a getter at

Fixes pouchdb#7688 and pouchdb#7727
  • Loading branch information
garfieldnate authored and sto3psl committed Mar 10, 2021
1 parent 9992954 commit fc08725
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/node_modules/pouchdb-adapter-http/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,16 +506,16 @@ function HttpPouch(opts, callback) {
var path = encodeDocId(doc._id) + '/' + encodeAttachmentId(filename) +
'?rev=' + doc._rev;
return ourFetch(genDBUrl(host, path)).then(function (response) {
if (typeof process !== 'undefined' && !process.browser) {
if ('buffer' in response) {
return response.buffer();
} else {
/* istanbul ignore next */
return response.blob();
}
}).then(function (blob) {
if (opts.binary) {
// TODO: Can we remove this?
if (typeof process !== 'undefined' && !process.browser) {
var typeFieldDescriptor = Object.getOwnPropertyDescriptor(blob.__proto__, 'type');
if (!typeFieldDescriptor || typeFieldDescriptor.set) {
blob.type = att.content_type;
}
return blob;
Expand Down Expand Up @@ -875,7 +875,7 @@ function HttpPouch(opts, callback) {
if (opts.descending) {
params.descending = true;
}

/* istanbul ignore if */
if (opts.update_seq) {
params.update_seq = true;
Expand Down

0 comments on commit fc08725

Please sign in to comment.