Question

there exist some sample code for an Http Server in the Dart:io section.

Now I will distribute images with this server. To achieve this, I read the requested image file and send its content to the client via request.response.write().

The problem is the format of the read data: Either I read the image file as 16bit-String or as Byte Array. Neither of them is compatible to a raw 8-bit array, which I have to send to the client.

May someone help me?

Was it helpful?

Solution

There exist several kinds of write-methods in the response class.

  1. write
  2. writeCharCode
  3. add

While "write" writes the data 'as seen', "writeCharCode" transforms the data back to raw-format. However, writeCharCode prepends some "magic byte" (C2) at the beginning, so it corrupts the data.

Another function, called add( List < int > ) processes the readAsBytes-result as desired.

Best regards, Alex

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top