read1
¶
Read bytes from a file or named pipe
read1 f read1[f]
read1 (f;o;n) read1[(f;o;n)]
read1 h read1[h]
read1 (fifo;n) read1[(fifo;n)]
Where
f
is a file symbol(f;o;n)
is a file descriptorh
is a system or process handlefifo
is a communication handle to a Fifon
is a non-negative integer
returns bytes from the source, as follows.
File¶
Where the argument is
- a file symbol, returns the entire content of the file
- a file descriptor
(f;o;n)
, returns up ton
bytes fromf
starting ato
- a file descriptor
(f;o)
, returns the entire content off
fromo
onwards
q)`:test.txt 0:("hello";"goodbye") / write some text to a file
q)read1`:test.txt / read in as bytes
0x68656c6c6f0a676f6f646279650a
q)"c"$read1`:test.txt / convert from bytes to char
"hello\ngoodbye\n"
q)/ read 500000 lines, chunks of (up to) 100000 at a time
q)d:raze{read1(`:/tmp/data;x;100000)}each 100000*til 5
Named pipe¶
(Since V3.4.) Where x
is
- a list
(fifo;length)
, returnslength
bytes read fromfifo
- an atom
fifo
, blocks and returns bytes fromfifo
when EOF is encountered (0#0x
if immediate)
q)h:hopen`$":fifo:///etc/redhat-release"
q)"c"$read1(h;8)
"Red Hat "
q)"c"$read1(h;8)
"Enterpri"
q)system"mkfifo somefifo";h:hopen`fifo:somefifo; 0N!read1 h; hclose h