* 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/
pgpxDkgIOrbzR.pgp
Description: PGP signature
_______________________________________________ Users-prolog mailing list [email protected] http://lists.gnu.org/mailman/listinfo/users-prolog
