REBOL 3.0

Should a binary datatype force binary port mode?

Carl Sassenrath, CTO
REBOL Technologies
27-Feb-2007 23:16 GMT

Article #0061
Main page || Index || Prior Article [0060] || Next Article [0062] || 13 Comments || Send feedback

First, some info:

In REBOL 3.0, port modes can be modified after the open has been done.

This example reads 100 bytes in string (text) mode, then reads 1024 bytes in binary mode:

file: open %file.txt
str: read/part file 100
bin: read/binary/part file 1024
Note

Note the use of read rather than copy in this example (because copy does not have a /binary refinement). Also, note that the contents of str can be less than 100 due to line termination conversion. The 100 refers to the number of bytes in the file itself.

Question:

With this capability in mind, it is possible for write to automatically change modes based on its argument. For example, we can detect a binary type and force the write to be binary.

Using the contents of the above example to illustrate:

ofile: open %out
write ofile str
write ofile bin  ; in /binary mode

The first part is written in string (text) mode with line conversions. The second part is written as binary, without conversions. (And, of course we will continue to allow /binary to be used to always write as binary.)

If we decide to allow it, we will probably also support:

write %out bin  ; uses /binary mode

The binary is written to the file without line conversion.

Do we want to allow this feature in REBOL 3.0?

13 Comments

REBOL 3.0
Updated 27-Mar-2024 - Edit - Copyright REBOL Technologies - REBOL.net