pub const STREAM: &str = "\"The SPL stream is an IO construct used to read and write to \";\n\"some external thing, for example a file or a TCP socket.\";\n\n\"All functions here are encapsulations of their native counterparts.\";\n\n\"Examples:\";\n\"def tcp \'localhost\' 8080 StreamType:tcp:create =tcp\";\n\"def file \'test.txt\' 1 StreamType:file:create =file \'hi\':to-bytes file:write-exact; file:close null =file\";\n\nconstruct Stream {\n id \n ;\n construct { this | with type this ;\n type new-stream this:=id\n this\n }\n read-one { mega | with this ;\n def buf 1 banew =buf\n while { buf this:id read-stream pop not } { }\n 0 buf:get _mega\n }\n \"the buffer is written to in-place.\";\n read { mega [int] | with buf this ;\n buf gettype \"mega\" eq if { buf banew =buf }\n buf this:id read-stream\n }\n \"the buffer is written to in-place.\";\n read-exact { [int] | with buf this ;\n buf gettype \"mega\" eq if { buf banew =buf }\n buf this:id read-all-stream buf\n }\n read-to-end { [int] | with buf this ;\n buf gettype \"mega\" eq if { buf banew =buf }\n def read\n 0 banew while { buf this:id read-stream pop _mega dup =read } {\n (0 read buf:sub) aadd\n }\n }\n write { mega | with buf this ;\n buf this:id write-stream\n }\n write-exact { | with buf this ;\n buf this:id write-all-stream\n }\n flush { | with this ;\n this:id flush-stream\n }\n shutdown-input { | with this ;\n this:id shutdown-input-stream\n }\n close { | with this ;\n this:id close-stream\n }\n peer { StreamPeer | with this ;\n this:id get-stream-peer StreamPeer:new\n }\n}\n\nconstruct StreamPeer {\n ip\n port\n ;\n construct { this | with ip port this ;\n ip this:=ip\n port this:=port\n this\n }\n _str { str | with this ;\n this:ip \":\" concat this:port _str concat\n }\n}\n\nconstruct StreamType {\n id \n ;\n construct { this | with id this ;\n id this:=id\n this\n }\n create { Stream | with this ;\n this:id Stream:new\n }\n}\n\ndef stream-types 0 anew =stream-types\n\nconstruct _StreamTypes {\n ;\n construct { this | with this ;\n { | with type ;\n \"type StreamType:new this:=<type>\";\n (type StreamType:new) (this (\"=\" type concat)) dyn-objcall\n } stream-types:foreach\n this\n }\n}\n\nfunc register-stream-type { | with id ;\n stream-types [ id ] aadd =stream-types\n id _StreamTypes dyn-def-field\n}\n\n\"tcp\" register-stream-type\n\"udp\" register-stream-type\n\"file\" register-stream-type\n\"cmd\" register-stream-type\n\nfunc StreamTypes { _StreamTypes |\n _StreamTypes:new\n}\n";