daleharvey/pouchdb — pull request #1210 by nolanlawson (2014-01-05 01:07:14+00:00)
Title: WIP: fix attachments in websql

Currently, ```test.attachments.js``` breaks in Safari (and websql in general) [at this test](https://github.com/daleharvey/pouchdb/blob/702e79f601915d9c82fa4dffff6ff65bb2a5a53b/tests/test.attachments.js#L197). I also see this in the Android stock browser (4.4 KitKat).

The issue is really subtle and annoying: it's that the blob data gets converted to UTF8 (!) before being encoded to binary. I have a solution, but it has the following limitations:

1. Assumes blobSupport in websql.
2. Doesn't work in leveldb yet. (@daleharvey, @calvinmetcalf: how do you guys debug ```npm test```? Can't seem to get node-inspector to work...)

Details for those who are interested: [the little png](https://github.com/daleharvey/pouchdb/blob/702e79f601915d9c82fa4dffff6ff65bb2a5a53b/tests/test.attachments.js#L60) gets UTF8-encoded, so all the high ASCII characters get corrupted, and it turns into:

```
wolQTkcNChoKAAAADUlIRFIAAAAQAAAAEAgDAAAAKC0PUwAAADBQTFRFw77Dt8Oow77DtMOgw77DrsOSw73DpsK6w73DnsKkw7zDkcKAw7vDh2LDusK+ScO6wrMsw7nCqRTDuMKiBMO4wp8Aw7jCngDDuMKdAMO4wp0Aw7jCnQDDk8OadMO/AAAAcElEQVQYw5NNwo5RAsOEQARDw4NQw7XDocO+w5fDnTDCnW3Ds8OnwoUEw6ojwpUqwrxjwpYjPyAAwoXDhR/DnMOmC8Ktw5dHJMOsOsOAwpbCk2A9GcKuw7AJeUDDtm3CksOobgnClVwQwpLCnD9ibGtSA2gywozCsQcEwowfw7XCpwM8wrlyd8OLFsOvwp0raXnCgMOLw648YsOGJcOdf8O0A8KiBQjChMKCTMOOwqYAAAAASUVORMKuQmDCgg==
```
Undoubtedly this is related to #895 and #1008; we'll probably be able to close all three when this is fixed.