Documentation for routine
slurp assembled from the following types:
Slurps the contents of the entire file into a
:enc optional named parameters, with the same meaning as open(). The routine will
fail if the file does not exist, or is a directory.
# read entire file as (Unicode) Strmy = slurp "path/to/file";# read entire file as Latin1 Strmy = slurp "path/to/file", enc => "latin1";# read entire file as Bufmy = slurp "path/to/file", :bin;
method slurp(IO::Handle: :, :)
Returns all the content from the current file position to the end. If the invocant is in binary mode or if
$bin is set to
True, will return a Buf, otherwise will decode the content using invocant's current
.encoding and return a Str.
:$close is set to
True, will close the handle when finished reading.
Note: On Rakudo this method was introduced with release 2017.04 and
$bin arg was added in 2017.10.
(my = 'foo'.IO).spurt: 'foo';(my = 'bar'.IO).spurt: 'bar';IO::CatHandle.new( , ).slurp.say; # OUTPUT: «foobar␤»IO::CatHandle.new(:bin, , ).slurp.say; # OUTPUT: «Buf[uint8]:0x<66 6f 6f 62 61 72>␤»IO::CatHandle.new .slurp.say; # OUTPUT: «Nil␤»
multi method slurp(IO::Path: :, :)