stream.bend relies on unsafe/foreign
raw source on the hub · import bend-kit-stream@0.5.0.2/stream.bend as Stream
Bounded packed-byte transfers between files and TCP/TLS sockets.
4 imports
import Base import ./pure.bend as Pure import bend-kit-files@0.4.0.2/files.bend as Files import bend-kit-wire@0.4.8.1/wire.bend as Wire
Types
type Error source · line 7 · raw
Data
BadChunkError
LimitError
Read@code:U32 -> @message:String -> Error
Write@code:U32 -> @message:String -> Error
type Outcome source · line 13 · raw
Data
Complete@count:U32 -> Outcome
Failed@count:U32 -> @error:Error -> Outcome
type Transfer source · line 17 · raw
@-S:Type -> @-D:Type -> Type
More@-S:Type -> @-D:Type -> @source:S -> @destination:D -> @count:U32 -> Transfer<S, D>
Stop@-S:Type -> @-D:Type -> @source:S -> @destination:D -> @outcome:Outcome -> Transfer<S, D>
Definitions
def file.read source · line 21 · raw
@source:File -> @max:U32 -> @tls:Bool -> @ms:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>))
def file.write source · line 25 · raw
@destination:File -> @len:U32 -> @words:Array<U32> -> @tls:Bool -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Unit>))
def socket.read.tls source · line 29 · raw
@tls:Bool -> @source:Socket -> @max:U32 -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>))
def socket.read source · line 37 · raw
@source:Socket -> @max:U32 -> @tls:Bool -> @ms:U32 -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>))
def socket.write.tls source · line 41 · raw
@tls:Bool -> @destination:Socket -> @len:U32 -> @words:Array<U32> -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))
def socket.write source · line 49 · raw
@destination:Socket -> @len:U32 -> @words:Array<U32> -> @tls:Bool -> IO(Pair(Socket, Result<&1, &1, Pair(U32, String), Unit>))
def file.file source · line 129 · raw
@source:File -> @destination:File -> @+chunk:U32 -> @cap:U32 -> IO(Pair(File, Pair(File, Outcome)))
Return both handles on every outcome; never close or retry a failed chunk.
def file.socket source · line 134 · raw
@source:File -> @destination:Socket -> @tls:Bool -> @+chunk:U32 -> @cap:U32 -> IO(Pair(File, Pair(Socket, Outcome)))
def socket.file source · line 140 · raw
@source:Socket -> @destination:File -> @tls:Bool -> @+chunk:U32 -> @cap:U32 -> @ms:U32 -> IO(Pair(Socket, Pair(File, Outcome)))
ms is the unchanged per-read Wire deadline, including the one-byte cap probe.
Templates
template transfer.written source · line 53 · raw
@-S:Type -> @-D:Type -> @source:S -> @count:U32 -> @len:U32 -> @pair:Pair(D, Result<&1, &1, Pair(U32, String), Unit>) -> Transfer<S, D>
template transfer.action source · line 62 · raw
@-S:Type -> @-D:Type -> @-write:(@_:D -> @_:U32 -> @_:Array<U32> -> @_:Bool -> IO(Pair(D, Result<&1, &1, Pair(U32, String), Unit>))) -> @action:0x4d062ec616c9473c5f509e7276c67271/pure.ReadAction -> @source:S -> @destination:D -> @count:U32 -> @+len:U32 -> @words:Array<U32> -> @tls:Bool -> IO(Transfer<S, D>)
template transfer.read source · line 76 · raw
@-S:Type -> @-D:Type -> @-write:(@_:D -> @_:U32 -> @_:Array<U32> -> @_:Bool -> IO(Pair(D, Result<&1, &1, Pair(U32, String), Unit>))) -> @pair:Pair(S, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>) -> @destination:D -> @count:U32 -> @remaining:U32 -> @tls:Bool -> IO(Transfer<S, D>)
template transfer.loop source · line 90 · raw
@-S:Type -> @-D:Type -> @-read:(@_:S -> @_:U32 -> @_:Bool -> @_:U32 -> IO(Pair(S, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>))) -> @-write:(@_:D -> @_:U32 -> @_:Array<U32> -> @_:Bool -> IO(Pair(D, Result<&1, &1, Pair(U32, String), Unit>))) -> @fuel:Nat -> @state:Transfer<S, D> -> @+tls:Bool -> @+chunk:U32 -> @+cap:U32 -> @+ms:U32 -> IO(Pair(S, Pair(D, Outcome)))
cap+1 reads suffice even if every successful nonempty read contains one byte. Fuel is first among runtime parameters; no fixed read ceiling or unsafe recursion.
template transfer.start source · line 116 · raw
@-S:Type -> @-D:Type -> @-read:(@_:S -> @_:U32 -> @_:Bool -> @_:U32 -> IO(Pair(S, Result<&1, &1, Pair(U32, String), Pair(U32, Array<U32>)>))) -> @-write:(@_:D -> @_:U32 -> @_:Array<U32> -> @_:Bool -> IO(Pair(D, Result<&1, &1, Pair(U32, String), Unit>))) -> @valid:Bool -> @source:S -> @destination:D -> @tls:Bool -> @chunk:U32 -> @+cap:U32 -> @ms:U32 -> IO(Pair(S, Pair(D, Outcome)))