Skip to content

Commit

Permalink
update get attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
stockulus committed Sep 9, 2016
1 parent 884ac76 commit 3b6fa09
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/pouchdb-adapter-asyncstorage/src/get_attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,26 @@ export default function (db, docId, attachId, attachment, opts, callback) {
if (!data || !data.data) {
return callback(null,
opts.binary
? global.Buffer.alloc(0, null, type)
? getEmptyBuffer(type)
: '')
}

callback(null,
opts.binary
? global.Buffer.from(data.data, 'base64')
? getBuffer(data.data, type)
: data.data
)
})
}

const getEmptyBuffer = type => {
const buffer = global.Buffer.alloc(0, null, type)
buffer.type = type
return buffer
}

const getBuffer = (base64Data, type) => {
const buffer = global.Buffer.from(base64Data, 'base64')
buffer.type = type
return buffer
}

0 comments on commit 3b6fa09

Please sign in to comment.