2

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?

Alex R.
  • 205
  • 1
  • 10
  • 1
    And what exactly is wrong with the byte (byte=8bit) array? The type is only List because there is no byte datatype, the possible values in the list still only range from 0-255. I think your problem is using `write()` instead of `writeCharCode()` – MarioP Jun 14 '13 at 15:29
  • Thank you very much for pointing on the writing function. In fact, writeCharCode prepends some wrong byte at the beginning of the image data. Instead I used request.response.write() to send the image and it worked. Regards – Alex R. Jun 17 '13 at 07:33

1 Answers1

2

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

Alex R.
  • 205
  • 1
  • 10