How do response.send a TypedArray?

#1

I’m trying to send a short typed array in response.send. It keeps being serialised to JSON

0 Likes

#2

If you use response.send() then it is the same as if you call response.json().

0 Likes

#3

Then, how do I send anything without serialising it or turning it into a string?

0 Likes

#4

Not sure but maybe you could use something like this:

response.json({
  data: myArray
})

On the client side you can cast data from string to array.

0 Likes

#5

This is not an option for me.

I decided to simply use response.write while using a setInterval for now.

0 Likes

#6

Http doesn’t have data types, it’s all text. Data types exists in a programming language and not at the HTTP transport layer.

What you need to do is send binary data as response and handling of binary data depends upon the client making the request. If you are making an Ajax request, then it will be handled differently and if you are making request from native platform like Android, then it will be handled differently.

So please share more info

1 Like

#7

The client is written in C and is more than a decade old. I can’t change anything on its side. So the format of data sent will stay the same. It has to be raw bytes without string conversion.

Converting binary data to a string is a not a valid option in JS. Unlike PHP or some other languages, a string to byte value and reverse conversion in JS may not go 1-to-1.

0 Likes