Skip to content

Instantly share code, notes, and snippets.

@xMartin
Created February 19, 2016 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xMartin/cac25bdddf943179badb to your computer and use it in GitHub Desktop.
Save xMartin/cac25bdddf943179badb to your computer and use it in GitHub Desktop.
crypto-pouch binary attachments
<!DOCTYPE html>
<script src="node_modules/pouchdb/dist/pouchdb.js"></script>
<script src="node_modules/crypto-pouch/bundle.js"></script>
<script>
var db = new PouchDB('db')
PouchDB.plugin(crypto)
var id = 'id-' + PouchDB.utils.uuid()
db.crypto('secretSecureEncryptionKey')
.then(function () {
var attachment = new Blob(['Is there life on Mars?'], {type: 'text/plain'});
return db.put({
_id: id,
_attachments: {
'att.txt': {
content_type: 'text/plain',
data: attachment
}
}
})
})
.then(function () {
return db.get(id, {
attachments: true,
binary: true
}).then(function (doc) { return doc._attachments['att.txt'].data})
})
.catch(function (error) {
console.log('\n db1: error ==============================')
console.log(error)
})
.then(function (doc) {
console.log('\ndb1: doc created ==============================')
console.log(doc)
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment