Documentation for method encoding

Documentation for method encoding, assembled from the following types:

class IO::Handle

From IO::Handle

(IO::Handle) method encoding

Defined as:

multi method encoding(IO::Handle:D: --> Str:D)
multi method encoding(IO::Handle:D: Str:D $enc --> Str:D)

Returns a Str representing the encoding currently used by the handle, defaulting to "utf8". A special value "bin" indicates the file handle is currently in binary mode. Specifying an optional positional $enc argument switches the encoding used by the handle.

    with 'foo'.IO {
        .spurt: "First line is text, then:\nBinary";
        my $fh will leave {.close} = .open;
        $fh.get.say;         # OUTPUT: «First line is text, then:␤» 
        $fh.encoding: 'bin';
        $fh.slurp.say;       # OUTPUT: «Buf[uint8]:0x<42 69 6e 61 72 79>␤»