[TIMOB-9159] Ti API: Easier way to convert between Blobs and Buffers
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | High |
Status | Open |
Resolution | Unresolved |
Affected Version/s | Release 1.8.0 |
Fix Version/s | n/a |
Components | TiAPI |
Labels | n/a |
Reporter | Arthur Evans |
Assignee | Unknown |
Created | 2012-05-16T16:34:03.000+0000 |
Updated | 2018-02-28T20:04:07.000+0000 |
Description
To go from a Buffer to a Blob we have Buffer.toBlob. However, there's no matching Blob.toBuffer. This would be handy since Buffers are more easily mutable than blobs, and some methods only accept one type or the other.
I think the current workaround for Blob > Buffer is something like:
var blobStream = Ti.Stream.createStream({ source: myBlob, mode: Ti.Stream.MODE_READ });
var newBuffer = Ti.createBuffer({ length: myBlob.length });
var bytes = blobStream.read(newBuffer);
This is muy ugly. It seems like it would be a lot simpler to add support for creating a buffer from a Blob in Ti.createBuffer:
var buffer = Ti.createBuffer({ value: myBlob });
No comments