Skip to content

Commit 3b6fa09

Browse files
committed
update get attachment
1 parent 884ac76 commit 3b6fa09

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/pouchdb-adapter-asyncstorage/src/get_attachment.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,26 @@ export default function (db, docId, attachId, attachment, opts, callback) {
1616
if (!data || !data.data) {
1717
return callback(null,
1818
opts.binary
19-
? global.Buffer.alloc(0, null, type)
19+
? getEmptyBuffer(type)
2020
: '')
2121
}
2222

2323
callback(null,
2424
opts.binary
25-
? global.Buffer.from(data.data, 'base64')
25+
? getBuffer(data.data, type)
2626
: data.data
2727
)
2828
})
2929
}
30+
31+
const getEmptyBuffer = type => {
32+
const buffer = global.Buffer.alloc(0, null, type)
33+
buffer.type = type
34+
return buffer
35+
}
36+
37+
const getBuffer = (base64Data, type) => {
38+
const buffer = global.Buffer.from(base64Data, 'base64')
39+
buffer.type = type
40+
return buffer
41+
}

0 commit comments

Comments
 (0)