Url

interface Url

A parsed source/sink locator, as accepted by the ISO SourceSink argument of open/3,4 and consult/1 (see it.unibo.tuprolog.solve.libs.io.primitives.IOPrimitiveUtils.ensuringArgumentIsUrl), and the type this module's stream-opening functions (openInputChannel, openOutputChannel) operate on.

A Url is platform-specific under the hood (JVM instances wrap java.net.URL, JS instances are hand-parsed), but this interface is what every predicate implementation is actually written against; build one via of (which also accepts bare file paths, not just file://-prefixed ones), file, remote, http, or https.

See also

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val host: String

The host component of this Url, or the empty string for isFile URLs.

Link copied to clipboard
open val isFile: Boolean

Whether this Url's protocol is "file".

Link copied to clipboard
open val isHttp: Boolean

Whether this Url's protocol starts with "http" (i.e. is "http" or "https").

Link copied to clipboard
abstract val path: String

The path component of this Url, e.g. /path/to/resource.

Link copied to clipboard
abstract val port: Int?

The port component of this Url, or null if unspecified.

Link copied to clipboard
abstract val protocol: String

The scheme this Url uses, e.g. "file", "http", "https".

Link copied to clipboard
abstract val query: String?

The query component of this Url (everything between ? and an optional #anchor), or null if absent.

Functions

Link copied to clipboard
open operator fun div(child: String): Url

Operator alias for resolve, so that url / "child" reads like a path-append.

Link copied to clipboard

Under Node, streams a local file lazily off disk. Everywhere else (browser-local or any remote resource), eagerly reads the whole resource via Url.readAsText into an in-memory InputChannel instead, since Okio has no synchronous file system for browsers and this module has no HTTP streaming client (see fetch).

Streams a local file lazily off disk via LocalFileSystem; for any non-Url.isFile URL (http(s), ...), lazily streams from java.net.URL.openStream, unlike the JS implementation which eagerly buffers remote resources in full.

Link copied to clipboard
expect fun Url.openOutputChannel(append: Boolean = false): OutputChannel<String>

Opens this Url for writing (or, if append, for appending), e.g. to back open(Url, write, Stream) (see it.unibo.tuprolog.solve.libs.io.primitives.Open3).

Only supported for local files under Node: browsers have no writable local file system, and this module never supports writing to remote resources (on any platform).

Only supported for Url.isFile URLs: writing to a remote resource is never supported (on any platform).

Link copied to clipboard
abstract fun readAsByteArray(): ByteArray

Eagerly fetches the resource this Url points to, as raw bytes.

Link copied to clipboard
abstract fun readAsText(): String

Eagerly fetches the resource this Url points to, decoded as UTF-8 text.

Link copied to clipboard
open fun resolve(child: String): Url

Builds the Url obtained by appending child as a further path segment of this one.

Link copied to clipboard
fun Url.toURL(): URL

Unwraps this Url into a plain java.net. URL, for interop with JVM APIs that require one.