URL

Usage

use URL;

or

import URL;

Download data from a URL or upload data to a URL.

For example, the following program downloads a web-page from http://example.com and outputs each line to stdout:

use URL;
var urlreader = openUrlReader("http://example.com");
var str:bytes;
// Output each line read from the URL to stdout
while(urlreader.readLine(str)) {
  write(str);
}

Note

This module is currently implemented using Curl. As such, please see the Curl documentation to see which protocols are available.

proc openUrlReader(url: string, param kind = iokind.dynamic, param locking = true, start: int(64) = 0, end: int(64) = max(int(64)), style: iostyle): fileReader(kind, locking) throws

Warning

openUrlReader with a style argument is unstable

proc openUrlReader(url: string, param kind = iokind.dynamic, param locking = true, start: int(64) = 0, end: int(64) = max(int(64))): fileReader(kind, locking) throws

Open a fileReader from a particular URL.

Arguments
  • url – which url to open (for example, “http://example.com”).

  • kindiokind compile-time argument to determine the corresponding parameter of the fileReader type. Defaults to iokind.dynamic, meaning that the associated iostyle controls the formatting choices.

  • locking – compile-time argument to determine whether or not the channel should use locking; sets the corresponding parameter of the fileReader type. Defaults to true, but when safe, setting it to false can improve performance.

  • start – zero-based byte offset indicating where in the file the fileReader should start reading. Defaults to 0.

  • end – zero-based byte offset indicating where in the file the fileReader should no longer be allowed to read. Defaults to a max(int) - meaning no end point.

Returns

an open fileReader to the requested resource.

Throws

SystemError – Thrown if a fileReader could not be returned.

proc openUrlWriter(url: string, param kind = iokind.dynamic, param locking = true, start: int(64) = 0, end: int(64) = max(int(64)), style: iostyle): fileWriter(kind, locking) throws

Warning

openUrlWriter with a style argument is unstable

proc openUrlWriter(url: string, param kind = iokind.dynamic, param locking = true, start: int(64) = 0, end: int(64) = max(int(64))): fileWriter(kind, locking) throws

Open a fileWriter to a particular URL.

Arguments
  • path – which file to open (for example, “ftp://127.0.0.1/upload/test.txt”)

  • kindiokind compile-time argument to determine the corresponding parameter of the fileWriter type. Defaults to iokind.dynamic, meaning that the associated iostyle controls the formatting choices.

  • locking – compile-time argument to determine whether or not the fileWriter should use locking; sets the corresponding parameter of the fileWriter type. Defaults to true, but when safe, setting it to false can improve performance.

  • start – zero-based byte offset indicating where in the file the fileWriter should start writing. Defaults to 0.

  • end – zero-based byte offset indicating where in the file the fileWriter should no longer be allowed to write. Defaults to a max(int) - meaning no end point.

Returns

an open fileWriter to the requested resource.

Throws

SystemError – Thrown if a fileWriter could not be returned.