Binary with_output_to/2

For some unit tests, I want to write to a binary list of codes. But it seems that with_output_to(codes(Stream), ...) does some kind of encoding (UTF8, I suppose).

I can make my unit test with tmp_file_stream/3 and the option encoding(binary), but that’s a bit clumsy; it would be nice if I could set the encoding of a “codes” stream, but that gets the error “No permission to encoding stream ‘current_output’”. (And a minor incompatibility: tmp_file_stream/3 has encoding(binary) but open/4, with_output_to/2, set_stream/2 have encoding(octet).)

Specifically, this is what I tried to do, and got an error:

                   (   set_stream(current_output, encoding(octet)),
                       ffi_write_int64(current_output, V)

Not sure this is useful enough to add the complications. Note that both memory files and temporary files can do what you need.

tmp_file_stream/3 also accepts encoding(octet). Not sure why it accepts binary as well. Might be history …

library(memfile) has memory_file_to_codes/3, which allows specifying an encoding, which does just what I want with encoding octet.