Reputation: 2965
How do I perform a fast copy of the bytes of a ByteBuffer into another larger ByteBuffer (at non-zero offset) in Dart?
There are slow ways to do this. One is to cast each to a Uint8List and copy over one index at a time. Another is to cast into each into a Uint8List, get an iterator for the first, and call setRange()
on the second.
I'm thinking there ought to be a more direct way that asks the Dart API to speedily copy a byte sequence from one buffer to the other. The API can natively optimize this copy. If not, what's the fastest way to do this?
Upvotes: 6
Views: 393
Reputation: 318
Try this, it should be faster than copy Uint8List value by value for larger dataset.
String url = Url.createObjectUrlFromBlob(new Blob([srcBuffer]));
ByteBuffer dstBuffer = (await HttpRequest.request(url, responseType: 'arraybuffer')).response;
Url.revokeObjectUrl(url);
Upvotes: 1