Support sending ArrayBuffers #11

Merged
merged 4 commits into from May 28, 2015

Conversation

Projects
None yet
2 participants
@DamianMehers
Contributor

DamianMehers commented May 28, 2015

This patch allows sending of binary data. Previously everything was converted to strings.

@Katharine

View changes

javascript/xhr.py
+ data_array = uint8_array.create(uint8_array, (data,))
+ self._request.data = bytes(bytearray(data_array[str(x)] for x in xrange(data_array.length)))
+ else:
+ self._request.data =str(data)

This comment has been minimized.

@Katharine

Katharine May 28, 2015

Contributor

You dropped a space after the = here.

@Katharine

Katharine May 28, 2015

Contributor

You dropped a space after the = here.

@Katharine

View changes

javascript/xhr.py
@@ -164,7 +164,12 @@ def go():
def send(self, data=None):
if data is not None:
- self._request.data = str(data)
+ if str(data) == '[object ArrayBuffer]':

This comment has been minimized.

@Katharine

Katharine May 28, 2015

Contributor

This will break if someone happens to send the string "[object ArrayBuffer]". You want to check for a string type first:

if isinstance(data, basestring):
    self._request.data = str(data)
elif str(data) == '[object ArrayBuffer]':
    # ...
@Katharine

Katharine May 28, 2015

Contributor

This will break if someone happens to send the string "[object ArrayBuffer]". You want to check for a string type first:

if isinstance(data, basestring):
    self._request.data = str(data)
elif str(data) == '[object ArrayBuffer]':
    # ...

This comment has been minimized.

@DamianMehers

DamianMehers May 28, 2015

Contributor

How about I check like this, so that we don't convert twice?

if not isinstance(data, str) and str(data) == '[object ArrayBuffer]':
@DamianMehers

DamianMehers May 28, 2015

Contributor

How about I check like this, so that we don't convert twice?

if not isinstance(data, str) and str(data) == '[object ArrayBuffer]':

This comment has been minimized.

@Katharine

Katharine May 28, 2015

Contributor

Sure, but use basestring for your isinstance check.

@Katharine

Katharine May 28, 2015

Contributor

Sure, but use basestring for your isinstance check.

@Katharine

This comment has been minimized.

Show comment
Hide comment
@Katharine

Katharine May 28, 2015

Contributor

👍

Contributor

Katharine commented May 28, 2015

👍

Katharine added a commit that referenced this pull request May 28, 2015

Merge pull request #11 from DamianMehers/master
Support sending ArrayBuffers

@Katharine Katharine merged commit 4306d60 into pebble:master May 28, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment