Console IO

Console input and output functions

input

Prompts for and reads user input from the console.

prompt string to display as a prompt

returns string containing the user's input

File Operations

File system operations and file manipulation

file-uri//Open

Opens a file for reading.

path uri representing the file to open

returns native file object

Open %data/file.txt |type?
; returns native
Open %data/file.txt |kind?
; returns file

file-uri//Open\append

Opens a file for appending.

path uri representing the file to open for appending

returns native writer object

Open\append %data/file.txt |type?
; returns native
Open\append %data/file.txt |kind?
; returns writer

file-uri//Create

Creates a new file.

path uri representing the file to create

returns native file object

Create %data/created.txt |type?
; returns native
Create %data/created.txt |kind?
; returns file

file-uri//File-ext?

Gets the extension of a file.

path uri or string representing a file path

returns string containing the file extension (including the dot)

File-ext? %data/file.txt
; returns ".txt"
File-ext? %data/file.temp.png
; returns ".png"
File-ext? to-file "data/file.temp.png"
; returns ".png"

file-uri//Filename?

Gets the filename with extension from a file path.

path uri representing a file path

returns string containing the filename with extension

file-uri//Stem?

Gets the filename without extension from a file path.

path uri representing a file path

returns string containing the filename without extension

file-uri//Dir?

Gets the directory path from a file path.

path uri representing a file path

returns string containing the directory path

file-uri//Split

Splits a file path into its components.

path uri representing a file path

returns block of strings containing path components

file-uri//Is-absolute

Checks if a file path is absolute.

path uri representing a file path

returns boolean indicating whether the path is absolute

file//Reader

Creates a new reader from file object.

source file object to read from

returns native reader object

[Uri: data/file.txt] [Native of kind file]
Reader probe Open probe %data/file.txt |kind?
; returns reader

file//Writer

Creates a new reader from file object.

source file object to read from

returns native reader object

[Uri: data/file.txt] [Native of kind file]
Reader probe Open probe %data/file.txt |kind?
; returns reader

file-uri//Reader

Creates a new reader from a file uri/path.

source file uri to read from

returns native reader object

Reader %data/file.txt |kind?
; returns reader

reader

Creates a new reader from a string.

source string to read from

returns native reader object

reader "some string" |kind?
; returns reader

stdin

Gets a reader for standard input.

none

returns native reader object connected to standard input

stdout

Gets a writer for standard output.

none

returns native writer object connected to standard output

stderr

Gets a writer for standard error.

none

returns native writer object connected to standard error

reader//Read\string

Reads all content from a reader as a string.

reader native reader object

returns string containing all content from the reader

reader "some string" |Read\string
; returns "some string"

reader//Copy

Copies all content from a reader to a writer.

reader native reader object

writer native writer object

returns the reader object if successful

file//Copy

Copies content from a file to a writer.

file native file object

writer native writer object

returns the file object if successful

file//Stat

Gets file information (stat) for a file.

file native file object

returns native file-info object

Stat Open %data/file.txt |kind?
; returns file-info

file-info//Size?

Gets the size of a file in bytes.

file-info native file-info object

returns integer representing the file size in bytes

Size? Stat Open %data/file.txt
; returns 16

file//Read-all

Reads the entire content of a file as a string.

file native file object

returns string containing the entire file content

Read-all Open %data/file.txt
; returns "hello text file
; "

file//Seek\end

Seeks to the end of a file.

file native file object

returns the same file object with position set to end of file

file//Write

Writes a string directly to a file object.

file native file object

content string to write to the file

returns the file object if successful (allows chaining)

file//Close

Closes an open file.

file native file object

returns empty string if successful

Close Open %data/file.txt
; returns ""

file-uri//Read

Reads the entire content of a file as a string.

path uri representing the file to read

returns string containing the entire file content

Read %data/file.txt
; returns "hello text file
; "

file-uri//Read\bytes

Reads the entire content of a file as bytes.

path uri representing the file to read

returns native bytes object containing the file content

Read %data/file.txt
; returns "hello text file
; "

file-uri//Read\lines

Reads a file and returns its content as a block of lines.

path uri representing the file to read

returns block of strings, each representing a line from the file

Read %data/file.txt
; returns "hello text file
; "

file-uri//Write

Writes content to a file.

path uri representing the file to write to

content string or bytes to write to the file

returns the content that was written

Write %data/write.txt "written
"
; returns "written
; "

write\bytes

Writes bytes to a file.

bytes Go-bytes native value to write

path string path to the file to write

returns integer 1 if successful

append\bytes

Appends two byte arrays into one.

bytes1 first Go-bytes native value

bytes2 second Go-bytes native value

returns combined bytes as a native bytes object

writer//Write

Writes a string to a writer.

writer native writer object

content string to write

returns the writer object if successful

HTTPs Operations

Web requests and HTTP protocol functions

https-uri//Open

Opens a HTTPS GET request and returns a reader for the response body.

url uri representing the HTTPS URL to request

returns native reader object for the response body

https-uri//Get

Makes a HTTPS GET request and returns the response body as a string.

url uri representing the HTTPS URL to request

returns string containing the response body

https-uri//Post

Makes a HTTPS POST request and returns the response body as a string.

url uri representing the HTTPS URL to request

data string containing the request body

content-type word specifying the content type (e.g., 'json', 'text')

returns string containing the response body

http-uri//Get

Makes a HTTP GET request and returns the response body as a string.

url uri representing the HTTP URL to request

returns string containing the response body

http-uri//Post

Makes a HTTP POST request and returns the response body as a string.

url uri representing the HTTP URL to request

data string containing the request body

content-type word specifying the content type (e.g., 'json', 'text')

returns string containing the response body

https-uri//Request

Creates a new HTTPS request object.

url uri representing the HTTPS URL to request

method word specifying the HTTP method (e.g., 'GET', 'POST')

data string containing the request body

returns native https-request object

https-request//Header!

Sets a header on a HTTPS request.

request native https-request object

name word representing the header name

value string containing the header value

returns the request object if successful

https-request//Basic-auth!

Sets Basic Authentication on a HTTPS request.

request native https-request object

username string containing the username

password string containing the password

returns the request object if successful

https-request//Call

Executes a HTTPS request and returns the response object. Always returns the response regardless of status code (200, 404, 500, etc.) - use Status? to check the code.

request native https-request object

returns native https-response object (always returns response regardless of status code)

https-response//Reader

Gets a reader for the HTTPS response body that can be used with io.Copy.

response native https-response object

returns native reader object for the response body

https-response//Read-body

Reads the body of a HTTPS response as a string.

response native https-response object

returns string containing the response body

Email Operations

Email sending and SMTP communication

email//Send

Sends an email to the specified address.

to email address to send to

message string containing the email message

returns integer 1 if successful

FTP Operations

File Transfer Protocol operations and connections

ftp-uri//Open

Opens a connection to an FTP server.

server uri representing the FTP server to connect to

returns native ftp-connection object

ftp-connection//Login

Logs in to an FTP server connection.

connection native ftp-connection object

username string containing the username

password string containing the password

returns the connection object if successful

ftp-connection//Retrieve

Retrieves a file from an FTP server.

connection native ftp-connection object

path string containing the path of the file to retrieve

returns native reader object for the retrieved file

File Monitoring

File watching and tailing operations

tail-file

Tails a file, following it for new content. Used for monitoring log files.

path uri or string representing the file to tail

follow boolean indicating whether to follow the file for new content

reopen boolean indicating whether to reopen the file if it's rotated

returns native tail-file object that can be used to read lines as they are added

tail-file//Read-line

Reads the next line from a tailed file. Blocks until a line is available.

tail native tail-file object

returns string containing the next line from the file, or nil if no more lines

tail-file//Close

Closes a tailed file, stopping the monitoring.

tail native tail-file object

returns empty string if successful

Command Operations

Running other programs

cmd

Create a command.

command block or list containing a command arguments

returns native command object

cmd { echo -n Hello World } |Output
; returns "Hello World"
cmd { echo -n Hello World |tr A-Z a-z |sed "s/hello/goodbye/" } |Output
; returns "goodbye world"
cmd { echo -n "1 + 1 =" { 1 + 1 } } |Output
; returns "1 + 1 = 2"
args: list { "two" "arguments" } cmd { printf "'%s' " ?args } |Output
; returns "'two' 'arguments' "

command//Dir!

Change the working directory of a command.

command native command object

dir path to the working directory

returns the original command object

cmd { pwd } |Dir! %/ |Output |trim
; returns "/"

command//Stdin!

Change the standard input of a command.

command native command object

input path to an input file, a native file object, or a reader

returns the original command object

command//Stdout!

Change the standard output of a command.

command native command object

output path to an output file, a native file object, or a writer

returns the original command object

command//Stderr!

Change the standard error of a command.

command native command object

output path to an output file, a native file object, or a writer

returns the original command object

command//Pipe

Pipe the output of the first command to the input of the second command.

c1 first command writing to the pipe

c2 second command reading from the pipe

returns new native command object

cmd { echo -n Hello World } |Pipe cmd { tr a-z A-Z } |Output
; returns "HELLO WORLD"

command//Run

Start a command and wait for it to finish.

command native command object

cmd { false } |Run
; correctly causes error:
; exit status 1 in builtin Run. 

command//Status

Start a command, wait for it to finish, and return its exit status.

command native command object

returns for simple command: exit status integerfor pipeline: list of exit status integers

cmd { true } |Status
; returns 0
cmd { false } |Status
; returns 1
cmd { false |true } |Status
; returns list { 1 0 }

command//Output

Start a command, wait for it to finish, and return its standard output

command native command object

returns string containing data written to the command's standard output

command//CombinedOutput

Start a command, wait for it to finish, and return its combined standard output and error

command native command object

returns string containing data written to the command's standard output and error

SQLite

SQLite database functions

sqlite-uri//Open

Opens a connection to a SQLite database file.

uri path to SQLite database file

returns native SQLite database connection

Open sqlite://test.db |type?
; returns native

htmlize

Converts a table to HTML format.

table table to convert to HTML

returns string containing HTML representation of the table

table { "name" "age" } { "Bob" 25 "Alice" 30 } |htmlize |type?
; returns string

Rye-sqlite//Exec

Executes a SQL statement that doesn't return rows.

db SQLite database connection

sql SQL statement as string or block

returns database connection

Open sqlite://test.db |Exec "CREATE TABLE IF NOT EXISTS test (id INTEGER, name TEXT)" |type?
; returns native

Rye-sqlite//Query

Executes a SQL query and returns results as a table.

db SQLite database connection

sql SQL query as string or block

returns table containing query results

Open sqlite://test.db |Query "SELECT * FROM test" |type?
; returns table

Rye-sqlite//Show-SQL

Generates and returns the SQL string without executing it.

db SQLite database connection

sql SQL query as string or block

returns string containing the generated SQL with parameters

id: 123 Open sqlite://test.db |Show-SQL { SELECT * FROM test WHERE id = ?id } |type?
; returns string

PostgreSQL

postgres-uri//Open

Opens a connection to a PostgreSQL database.

uri PostgreSQL connection string URI (format

returns native PostgreSQL database connection (type: "Rye-psql")error if connection fails

Rye-psql//Exec

Executes a SQL statement that modifies data (INSERT, UPDATE, DELETE).

db PostgreSQL database connection (type

sql SQL statement as string or block (for data modification

returns integer number of rows affectederror if execution fails

Open postgres://user:pass@localhost:5432/dbname
|Exec { INSERT INTO test VALUES ( 1 , "test" ) }
; mind the mandatory spacing in SQL dialect

Rye-psql//Query

Executes a SQL query and returns results as a table.

db PostgreSQL database connection (type

sql SQL query as string or block (SELECT statements)

returns table containing query results (SQL NULL values converted to Void{})error if query fails or returns no data

db: Open postgres://user:pass@localhost:5432/dbname
db .Query "SELECT * FROM test"

Rye-psql//Show-SQL

Generates and returns the SQL string without executing it.

db PostgreSQL database connection (type

sql SQL query as string or block (for debugging/inspection)

returns string containing the generated SQL with parameters (includes parameter comments if present)error if SQL is empty

name: "Bob"
Open postgres://user:pass@localhost:5432/dbname
|Show-SQL {  SELECT * FROM users WHERE first_name = ?name}

MySQL

MySQL database functions

mysql-uri//Open

Opens a connection to a MySQL database.

uri MySQL connection string URI

returns native MySQL database connection

Open mysql://user:pass@tcp(localhost)/dbname

mysql-uri//Open\pwd

Opens a connection to a MySQL database with separate password parameter.

uri MySQL connection string URI without password

password Password for the database connection

returns native MySQL database connection

equal { Open\pwd mysql://user@tcp(localhost:3306)/dbname" "password"

Rye-mysql//Exec

Executes a SQL statement that modifies data (INSERT, UPDATE, DELETE).

db MySQL database connection

sql SQL statement as string or block

returns integer 1 if rows were affected, error otherwise

Open mysql://user:pass@tcp(localhost:3306)/dbname" ,
|Exec { INSERT INTO test VALUES ( 1 , "test" ) }

Rye-mysql//Query

Executes a SQL query and returns results as a table.

db MySQL database connection

sql SQL query as string or block

returns table containing query results

id: 101
db: Open mysql://user:pass@tcp(localhost:3306)/dbname
db .Query { SELECT * FROM test where id = ?id }