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 locking = true, start: int(64) = 0, end: int(64) = max(int(64))) : fileReader(locking) throws

Warning

openUrlReader with a start and/or end argument is deprecated. Please use the new region argument instead.

proc openUrlReader(url: string, param locking = true, region: range(?) = 0..) : fileReader(locking) throws

Open a fileReader from a particular URL.

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

  • 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.

  • region – zero-based byte offset indicating where in the file the fileReader should read. Defaults to 0.. - meaning from the start of the file to no end point.

Returns:

an open fileReader to the requested resource.

Throws:

SystemError – If a fileReader could not be returned.

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

Warning

openUrlWriter with a start and/or end argument is deprecated. Please use the new region argument instead.

proc openUrlWriter(url: string, param locking = true, region: range(?) = 0..) : fileWriter(locking) throws

Open a fileWriter to a particular URL.

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

  • 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.

  • region – zero-based byte offset indicating where in the file the fileWriter should write. Defaults to 0.. - meaning from the start of the file to no end point.

Returns:

an open fileWriter to the requested resource.

Throws:

SystemError – If a fileWriter could not be returned.