MCPcopy Index your code
hub / github.com/pyscript/pyscript / as_bytearray

Function as_bytearray

core/src/stdlib/pyscript/util.py:19–29  ·  view source on GitHub ↗

Given a JavaScript `ArrayBuffer`, convert it to a Python `bytearray` in a MicroPython friendly manner.

(buffer)

Source from the content-addressed store, hash-verified

17
18
19def as_bytearray(buffer):
20 """
21 Given a JavaScript `ArrayBuffer`, convert it to a Python `bytearray` in a
22 MicroPython friendly manner.
23 """
24 ui8a = js.Uint8Array.new(buffer)
25 size = ui8a.length
26 ba = bytearray(size)
27 for i in range(size):
28 ba[i] = ui8a[i]
29 return ba
30
31
32class NotSupported:

Callers 3

arrayBufferMethod · 0.90
bytearrayMethod · 0.90
__getattr__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected