The slurp routine

Combined from primary sources listed below.

In class IO::Handle ( type/IO/Handle )§

See primary docmentation in context for method slurp.

method slurp§

method slurp(IO::Handle:D: :$close, :$bin)

Returns all the content from the current file pointer 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.

If :$close is set to True, will close the handle when finished reading.

Note: On Rakudo this method was introduced with release 2017.04; $bin arg was added in 2017.10.

In class IO::Handle ( type/IO/Handle )§

See primary docmentation in context for method slurp.

method slurp-rest§

multi method slurp-rest(IO::Handle:D: :$bin--> Buf)
multi method slurp-rest(IO::Handle:D: :$enc --> Str)

DEPRECATION NOTICE: this method is deprecated in the 6.d version. Do not use it for new code, use .slurp method instead.

Returns the remaining content of the file from the current file position (which may have been set by previous reads or by seek.) If the adverb :bin is provided a Buf will be returned; otherwise the return will be a Str with the optional encoding :enc.

In class IO::CatHandle ( type/IO/CatHandle )§

See primary docmentation in context for method slurp.

method slurp§

method slurp(IO::CatHandle:D:)

Reads all of the available input from all the source handles and returns it as a Buf if the handle is in binary mode or as a Str otherwise. Returns Nil if the source handle queue has been exhausted.

(my $f1 = 'foo'.IO).spurt: 'foo';
(my $f2 = 'bar'.IO).spurt: 'bar';

IO::CatHandle.new(      $f1, $f2).slurp.say# OUTPUT: «foobar␤»
IO::CatHandle.new(:bin, $f1, $f2).slurp.say# OUTPUT: «Buf[uint8]:0x<66 6f 6f 62 61 72>␤»
IO::CatHandle.new                .slurp.say# OUTPUT: «Nil␤»

In class IO::Path ( type/IO/Path )§

See primary docmentation in context for routine slurp.

routine slurp§

multi method slurp(IO::Path:D: :$bin, :$enc)

Read all of the file's content and return it as either Buf, if :$bin is True, or if not, as Str decoded with :$enc encoding, which defaults to utf8. File will be closed afterwards. See &open for valid values for :$enc.