http://www.faqs.org/rfcs/rfc2326.html <--- that should help you get started.
Basically from what i have done on streams, when i was making a file uploader, for anything like an image, you have to read it as bytes, which can be converted into an ASCII code but i found that when i converted it into an ACSII code and then re-byte'd it it didnt work, so you will have to be handling raw data.