txt: ## slurp.md
  slurp
  
  Combined from primary sources listed below.
  
  # [In IO::Handle](#___top "go to top of document")[§](#(IO::Handle)_method_slurp "direct link")
  
  See primary documentation
  [in context](/type/IO/Handle#method_slurp)
  for **method slurp**.
  
  ```raku
  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`](/type/Buf), otherwise will decode the content using invocant's current [`.encoding`](/routine/encoding) and return a [`Str`](/type/Str).
  
  If `:$close` is set to `True`, will close the handle when finished reading.
  
  **Note:** On [Rakudo](/language/glossary#Rakudo) this method was introduced with release 2017.04; `$bin` arg was added in 2017.10.
  
  # [In IO::CatHandle](#___top "go to top of document")[§](#(IO::CatHandle)_method_slurp "direct link")
  
  See primary documentation
  [in context](/type/IO/CatHandle#method_slurp)
  for **method slurp**.
  
  ```raku
  method slurp(IO::CatHandle:D:)
  ```
  
  Reads all of the available input from all the source handles and returns it as a [`Buf`](/type/Buf) if the handle is in [binary mode](/type/IO/CatHandle#method_encoding) or as a [`Str`](/type/Str) otherwise. Returns [`Nil`](/type/Nil) if the [source handle queue has been exhausted](/type/IO/CatHandle#method_next-handle).
  
  ```raku
  (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 IO::Path](#___top "go to top of document")[§](#(IO::Path)_routine_slurp "direct link")
  
  See primary documentation
  [in context](/type/IO/Path#routine_slurp)
  for **routine slurp**.
  
  ```raku
  multi method slurp(IO::Path:D: :$bin, :$enc)
  ```
  
  Read all of the file's content and return it as either [`Buf`](/type/Buf), if `:$bin` is `True`, or if not, as [`Str`](/type/Str) decoded with `:$enc` encoding, which defaults to `utf8`. File will be closed afterwards. See [`&open`](/routine/open) for valid values for `:$enc`.
  
  # [In Independent routines](#___top "go to top of document")[§](#(Independent_routines)_sub_slurp "direct link")
  
  See primary documentation
  [in context](/type/independent-routines#sub_slurp)
  for **sub slurp**.
  
  ```raku
  multi slurp(IO::Handle:D $fh = $*ARGFILES, |c)
  multi slurp(IO() $path, |c)
  ```
  
  Slurps the contents of the entire file into a [`Str`](/type/Str) (or [`Buf`](/type/Buf) if `:bin`). Accepts `:bin` and `:enc` optional named parameters, with the same meaning as [open()](/routine/open); possible encodings are the same as in all the other [`IO`](/type/IO) methods and are listed in [`encoding`](/type/IO/Handle#method_encoding) routine. The routine will `fail` if the file does not exist, or is a directory. Without any arguments, sub `slurp` operates on `$*ARGFILES`, which defaults to `$*IN` in the absence of any filenames.
  
  ```raku
  # read entire file as (Unicode) Str
  my $text_contents   = slurp "path/to/file";
  
  # read entire file as Latin1 Str
  my $text_contents   = slurp "path/to/file", enc => "latin1";
  
  # read entire file as Buf
  my $binary_contents = slurp "path/to/file", :bin;
  
  ```
  