Skip to content

Instantly share code, notes, and snippets.

@zoffixznet

zoffixznet/p6.p6 Secret

Created August 3, 2018 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/588fac94d26f6aa77d9941f4e64c1d1c to your computer and use it in GitHub Desktop.
Save zoffixznet/588fac94d26f6aa77d9941f4e64c1d1c to your computer and use it in GitHub Desktop.
unit class IO::String2 is IO::Handle;
has Buf $!content;
submethod TWEAK(:$buffer) {
$!content := Buf.new: $buffer.encode;
self.encoding: 'utf8'; # set up encoder/decoder
}
method open(|) { self }
method close(|) { self }
method opened { ! self.EOF }
method lock(| --> True) { }
method unlock( --> True) { }
method WRITE(\b --> True) { $!content.append: b }
method READ(\bytes) { $!content.splice: 0, bytes }
method EOF { not $!content }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment