Skip to content

Commit

Permalink
response.buffer() and blob.type have no/limited access in ReactNative
Browse files Browse the repository at this point in the history
response.buffer() is not supported at all, and blob.type is readonly in
ReactNative. Change the limited node/browser detection to (hopefully)
feature-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 committed Aug 3, 2019
1 parent a1bd30a commit 1806c2f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/node_modules/pouchdb-adapter-http/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,17 +506,17 @@ 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) {
blob.type = att.content_type;
var typeFieldDescriptor = Object.getOwnPropertyDescriptor(blob, 'type');
if (typeFieldDescriptor && typeFieldDescriptor.set) {
blob.type = contentType;
}
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 1806c2f

Please sign in to comment.