JsUrl

class JsUrl : Url

JS implementation of Url, hand-parsed via the WHATWG JsNativeUrl binding (there being no java.net.URL equivalent to wrap, unlike it.unibo.tuprolog.solve.libs.io.JvmUrl).

Its behavior further forks on isNode: readAsText/readAsByteArray read local (isFile) resources straight off disk (via LocalFileSystem) only under Node, fall back to window.localStorage for local resources in a browser, and otherwise eagerly fetch the remote resource in full, for both platforms.

Constructors

Link copied to clipboard
constructor(url: String)

Parses url, e.g. JsUrl("https://example.com/page").

constructor(protocol: String, host: String = "", port: Int? = null, path: String = "", query: String? = null)

Builds a JsUrl from its protocol/host/port/path/query components, via Url.toString.

Properties

Link copied to clipboard
open override 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
open override val path: String

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

Link copied to clipboard
open override val port: Int?

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

Link copied to clipboard
open override val protocol: String

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

Link copied to clipboard
open override 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
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
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
open override fun readAsByteArray(): ByteArray
Link copied to clipboard
open override fun readAsText(): String
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
open override fun toString(): String
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.