Wolfram Language

Read Both Text and Data over the Network

ReadByteArray can read bytes from a stream until a specified delimiter is reached. In this example, the text is read over an HTTP connection until the so-called "magic number" indicating the start of a GIF file is read, then the remaining bytes are converted to an image.

Open an HTTP connection.

Write a request to the socket.

A GIF file must always start with the bytes corresponding to the string "GIF89a".

Read until the byte sequence indicating the start of the GIF file is found.

Convert data in the HTTP header to text.

Read all remaining bytes.

Join the data bytes with the GIF header and import the images.

Close the socket.

Related Examples

ja