Re: handling mixed I/O.
Sylvain Soliman <[email protected]>
| Newsgroups | gmane.comp.gnu.prolog.general |
|---|---|
| Message-ID | <[email protected]> |
* Ferreira Maurizio <[email protected]>: > I need to do mixed (binary/text) output to a socket stream. > (I'm trying to develop a micro http server). ... > The problem arises when I need to output binary data (images). > The trouble is that I dont' know how to set the Output stream type. > if it has the default value (type=Text), I cannot copy on it the binary > data, > and if I set it in binary mode, I cannot use 'write' to write to it. > > Any suggetion ? What I did when facing the same problem (for the same purpose!) was to always write in binary mode (AFAIK it is not possible to dynamically change the type), so I just wrote a few helpers: ===== % same as 'format/3' and 'write/2' but with bytes instead of chars % for binary streams formatb(S,F,L):- format_to_atom(A,F,L), writeb(S,A). writeb(S,A):- atom_codes(A,C), put_bytes(S,C). put_bytes(_,[]). put_bytes(S,[B|L]):- put_byte(S,B), put_bytes(S,L). ===== Best, Sylvain -- Sylvain Soliman <[email protected]> Tel: (+33) 1 39635761 INRIA Paris-Rocquencourt - Equipe CONTRAINTES Fax: (+33) 1 39635469 Domaine de Voluceau, Rocquencourt, BP 105 GnuPG Public Key: 0x0F53AF99 78153 LE CHESNAY CEDEX - FRANCE http://contraintes.inria.fr/~soliman/ _______________________________________________ Users-prolog mailing list [email protected] http://lists.gnu.org/mailman/listinfo/users-prolog
signature.asc
(application/pgp-signature, 186 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (Darwin) iD8DBQFIDbvhu6JwgQ9Tr5kRAonQAKCe8NI9TrS6K/aLFG/XAyVSrbcfMACgq+pr FbYHcenJP7oZFO+4AK+v9uM= =p3RH -----END PGP SIGNATURE-----