~/bend-docscommunity

impl.bend relies on unsafe/foreign

raw source on the hub · import bend-stdio-pipes@0.1.0.0/impl.bend as Impl

THIS MODULE IS PROJECT-AGNOSTIC. KEEP IT THAT WAY. A POLYFILL: Bend has no pipes to a started program and no stdin handle yet. Delete this module when Base has them, and call Base instead. This program's stdin, and a started program's stdin and stdout, as Files; and the UTF-8 lines that come through them. A line has at most max bytes with its LF or CRLF: a longer one fails with E2BIG (7).

1 import
import Base

Definitions

def read_line.peeked source · line 29 · raw

@next:Pair(File, Result<&1, &1, Pair(U32, String), String>) -> @text:String -> Pair(File, Result<&1, &1, Pair(U32, String), Maybe<&1, String>>)

A line with no LF that ends the input is the last line; one that does not is too long.

def read_line.unended source · line 43 · raw

@+piece:String -> String

The line of a piece that ends with its LF: the piece without the LF, and the CR before it, if any.

def read_line.if source · line 52 · raw

@file:File -> @ended:Bool -> @piece:String -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Maybe<&1, String>>))

def read_line.got source · line 68 · raw

@got:Pair(File, Result<&1, &1, Pair(U32, String), String>) -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Maybe<&1, String>>))

def read_line source · line 81 · raw

@file:File -> @max:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Maybe<&1, String>>))

The next line of file, as it comes, without its LF or CRLF; None at the end of the file.

def write_lines.text source · line 89 · raw

@lines:List<&1, String> -> String

def write_lines source · line 97 · raw

@file:File -> @lines:List<&1, String> -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Unit>))

Writes each line to file, with its LF.

Effects (foreign code)

effect stdin source · line 13 · raw

IO(File)

This program's stdin. A File owns its descriptor: ask for it once.

foreign: std.c, std.js

effect open source · line 21 · raw

@program:String -> @args:List<&1, String> -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Pair(File, File))>)

Start a program, with its stdin and stdout as pipes: its process id, the File that writes its stdin, and the File that reads its stdout. Its stderr is ours. Closing the stdin File gives it EOF; nothing waits for it to exit. On JS, it runs on Bun on Linux and macOS only; elsewhere it fails with ENOSYS.

foreign: open.c, open.js