Skip to content

Os

This package provides an interface for operating systems.

{
"type": "system"
}
{
"dependencies": {
"Os": "pen:///os"
}
}

A context of an operating system.

type Context = context'Context

No functions are defined.

No types are defined.

Read a directory and return file paths it contains.

\(ctx Context, path string) [string] | error

Create a directory.

\(ctx Context, path string) none | error

Remove a directory.

\(ctx Context, path string) none | error

No types are defined.

Get command line arguments.

\(ctx Context) [string]

Get an environment variable.

\(ctx Context, name string) string | error

A file on a file system.

type File {
# ...
}

A file of standard input.

\() File

A file of standard output.

\() File

A file of standard error.

\() File

Open a file for read-only.

\(ctx Context, path string) File | error

Open a file with options.

\(ctx Context, path string, opt OpenOptions) File | error

Read a file.

\(ctx Context, file File) string | error

Read a file until a size limit.

\(ctx Context, file File, limit number) string | error

Write data to a file.

\(ctx Context, file File, data string) number | error

Copy a file to another path.

\(ctx Context, src string, dest string) none | error

Move a file to another path.

\(ctx Context, src string, dest string) none | error

Remove a file.

\(ctx Context, path string) none | error

Get metadata of a file at a path.

\(ctx Context, path string) Metadata | error

File metadata

type Metadata {
Size number
}

No functions are defined.

Options to open a file

  • Append allows appending data to the file.
  • Create creates a new file if the file doesn’t exist or opens it otherwise.
  • CreateNew creates a new file. If the file already exists, it emits an error.
  • Read allows reading data from the file.
  • Truncate truncates the file to zero byte.
  • Write allows writing data to the file.
type OpenOptions {
Append boolean
Create boolean
CreateNew boolean
Read boolean
Truncate boolean
Write boolean
}

Get default options to open a file. They do not include any permission.

\() OpenOptions

No types are defined.

Exit a current process.

\(ctx Context, code number) none

Run a command.

\(ctx Context, cmd string, args [string]) none | error

No types are defined.

Create a listener bound to a server address.

\(ctx Context, address string) Listener | error

Create a stream connected to a peer address.

\(ctx Context, address string) Stream | error

Accept a client connection and create its stream.

\(ctx Context, l Listener) AcceptedStream | error

Receive data from a peer through a stream with a size limit in bytes.

\(ctx Context, s Stream, limit number) string | error

Send data to a peer through a stream.

\(ctx Context, s Stream, data string) number | error

A TCP stream accepted on a server with a client address

type AcceptedStream {
Stream Stream
Address string
}

No functions are defined.

A TCP listener to listen for client connections

type Listener {
# ...
}

No functions are defined.

A TCP stream

type Stream {
# ...
}

No functions are defined.

No types are defined.

Fetch a current system time in milliseconds.

\(ctx Context) number

Pause a current execution context for a given amount of time.

\(ctx Context, milliseconds number) none

No types are defined.

Bind a socket with a server address.

\(ctx Context, address string) Socket | error

Connect a socket to a peer address.

\(ctx Context, s Socket, address string) none | error

Receive a datagram from a connected address.

\(ctx Context, s Socket) string | error

Receive a datagram from any address.

\(ctx Context, s Socket) Datagram | error

Send a datagram to a connected address.

\(ctx Context, s Socket, data string) number | error

Send a datagram to a specified address.

\(ctx Context, s Socket, data string, address string) number | error

UDP datagram

type Datagram {
Data string
Address string
}

No functions are defined.

UDP socket

type Socket {
# ...
}

No functions are defined.