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): channel(false, kind, locking) throws¶
Warning
openUrlReader with a style argument is deprecated
- proc openUrlReader(url: string, param kind = iokind.dynamic, param locking = true, start: int(64) = 0, end: int(64) = max(int(64))): channel(false, kind, locking) throws
Open a channel reading from a particular URL.
- Arguments
url – which url to open (for example, “http://example.com”).
kind –
iokind
compile-time argument to determine the corresponding parameter of thechannel
type. Defaults toiokind.dynamic
, meaning that the associatediostyle
controls the formatting choices.locking – compile-time argument to determine whether or not the channel should use locking; sets the corresponding parameter of the
channel
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 channel should start reading. Defaults to 0.
end – zero-based byte offset indicating where in the file the channel should no longer be allowed to read. Defaults to a
max(int)
- meaning no end point.
- Returns
an open reading channel to the requested resource.
- Throws
SystemError – Thrown if a reading channel 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): channel(true, kind, locking) throws¶
Warning
openUrlWriter with a style argument is deprecated
- proc openUrlWriter(url: string, param kind = iokind.dynamic, param locking = true, start: int(64) = 0, end: int(64) = max(int(64))): channel(true, kind, locking) throws
Open a channel writing to a particular URL.
- Arguments
path – which file to open (for example, “ftp://127.0.0.1/upload/test.txt”)
kind –
iokind
compile-time argument to determine the corresponding parameter of thechannel
type. Defaults toiokind.dynamic
, meaning that the associatediostyle
controls the formatting choices.locking – compile-time argument to determine whether or not the channel should use locking; sets the corresponding parameter of the
channel
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 channel should start writing. Defaults to 0.
end – zero-based byte offset indicating where in the file the channel should no longer be allowed to write. Defaults to a
max(int)
- meaning no end point.
- Returns
an open writing channel to the requested resource.
- Throws
SystemError – Thrown if a writing channel could not be returned.