I'm attempting to read a file into a list of bytes in prolog, using swipl version 8.0.3.
:- use_module(library(readutil)).
try_read_byte(File):-
open(File, read, Stream),
get_byte(Stream, B),
print(B).
try_read_char(File):-
open(File, read, Stream),
get_char(Stream, C),
print(C).
try_read_char
succeeds, but when I call try_read_byte
, I get an error:
ERROR: No permission to read bytes from TEXT stream `<stream>(0x56413a06a2b0)'
ERROR: In:
ERROR: [9] get_byte(<stream>(0x56413a06a2b0),_9686)
ERROR: [8] try_read_byte("test.pl") at /home/justin/code/decompile/test.pl:5
ERROR: [7] <user>
From reviewing the source code/documentation (https://www.swi-prolog.org/pldoc/man?section=error), it seems as if this is something like a type error, but I'm not able to figure out what to do based on that.
open(File, read, D, [type(binary)])
. But do you really want bytes? (this is not specific to SWI) – false