From 3b6fa09b9bce02f5bf830119af3bfc69af1f3eac Mon Sep 17 00:00:00 2001 From: stockulus Date: Fri, 9 Sep 2016 15:49:47 +0200 Subject: [PATCH] update get attachment --- .../src/get_attachment.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/pouchdb-adapter-asyncstorage/src/get_attachment.js b/packages/pouchdb-adapter-asyncstorage/src/get_attachment.js index 170b226..be092a5 100644 --- a/packages/pouchdb-adapter-asyncstorage/src/get_attachment.js +++ b/packages/pouchdb-adapter-asyncstorage/src/get_attachment.js @@ -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 +}