[plt-scheme] Writing Bytes into a file
For writing, you can encode an 8-bit integer into a char, and then
write that char to a file. Reading is similar. So for example, you
could use these functions:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define read-byte
(lambda (port)
(char->integer (read-char port))))
(define write-byte
(lambda (byte port)
(write-char (integer->char byte) port)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MzScheme also provides the "integer->integer-byte-string" and
"integer-byte-string->integer" functions which help when converting
values larger than 8-bits into low-level representations.
"Djos" <djos06 at wanadoo.fr> writes:
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> are there any fonctions like these , to write bytes into a file , with plt
> scheme ?
>
> (write-byte byte binary-output-port) ; writes an exact 8-bit integer and
> returns an unspecified value
> (read-byte binary-input-port) ; returns an exact integer, or an end-of-file
> object
>
> (I found these functions here :
> http://www.cs.hmc.edu/~fleck/envision/user-manual/binary-files.html )