The way I see it, there are two ways we could offer support for binary data.

1. The nice thing about File-objects in js is, that they implement the
Blob-interface, which can be converted to a binary string [0..255] by the
Filereader api. This is what I do in util methods before handing data to
the openpgp.js api.

We could simply add an additional function to the public api that accepts
the blobs instead of strings. This api function would basically invoke util
methods with the Filereader Api and then just call the openpgp.js with the
resulting string.

This would make file handling a breeze with the openpgp.js since the Blob
interface is used in all browser file-apis. The main drawback would be that
openpgp.js would need support for the Blob and the Filereader api. These
apis are common in browsers but not in other runtimes such as node.js.

2. We could add ArrayBuffer/Uint8Array support. Although these Apis arent
in node.js either, these are more generic/ lower-level concepts that are a
good fit for a library in my opinion. And I read somewhere that the node.js
community is discussing also using the ArrayBuffer apis instead of their
current Buffer api.

We could add support by offering a new function in the public api that
accepts an ArrayBuffer and invokes conversion to a string. But that could
be slow and block the main thread for large files. So if the runtime
supports them, we could use the BlobBuilder and FileReader Api which do
conversion natively and asynchronously.

Tankred
_______________________________________________

http://openpgpjs.org

Reply via email to