juno.net.client Module

Provides methods for sending data to and receiving data from a resource indentified by a URI.

Licence
See licence.txt for use and distribution terms.

ubyte[] downloadData(Uri address, void delegate(int percent, long bytesReceived, long bytesToReceive, ref bool abort) downloadProgress = null);
ubyte[] downloadData(char[] address, void delegate(int percent, long bytesReceived, long bytesToReceive, ref bool abort) downloadProgress = null);

Downloads the resource with the specified URI as a ubyte array.

Parameters
Uri address
The URI from which to download data.

Returns
A ubyte array containing the downloaded resource.

Examples
 import juno.net.core, std.stdio;

 void main() {
   auto remoteUri = new Uri("http://www.bbc.co.uk");

   auto data = downloadData(remoteUri);
   writefln(data);
 }

char[] downloadString(Uri address, void delegate(int percent, long bytesReceived, long bytesToReceive, ref bool abort) downloadProgress = null);
char[] downloadString(char[] address, void delegate(int percent, long bytesReceived, long bytesToReceive, ref bool abort) downloadProgress = null);

Downloads the resource with the specified URI as a string.

Parameters
Uri address
The URI from which to download.

Returns
A string containing the downloaded resource.

void downloadFile(Uri address, char[] fileName, void delegate(int percent, long bytesReceived, long bytesToReceive, ref bool abort) downloadProgress = null);
void downloadFile(char[] address, char[] fileName, void delegate(int percent, long bytesReceived, long bytesToReceive, ref bool abort) downloadProgress = null);

Downloads the resource with the specified URI to a local file.

Parameters
Uri address
The URI from which to download data.
char[] fileName
The name of a local file that is to receive the data.

Examples
 import juno.net.core, juno.io.path, std.stdio;

 void main() {
   string remoteUri = "http://www.bbc.co.uk/bbchd/images/headings/";
   string fileName = "logo.gif";

   downloadFile(remoteUri + fileName, fileName);

   writefln("File is saved in " ~ currentDirectory);
 }

ubyte[] uploadData(Uri address, ubyte[] data, void delegate(int percent, long bytesSent, long bytesToSend) uploadProgress = null);
ubyte[] uploadData(char[] address, ubyte[] data, void delegate(int percent, long bytesSent, long bytesToSend) uploadProgress = null);

Uploads a data buffer to a resource identified by a URI.

Parameters
Uri address
The URI of the resource to receive the data.
ubyte[] data
The data buffer to send to the resource.

Returns
A ubyte array containing the body of the response from the resource.

ubyte[] uploadString(Uri address, char[] data, void delegate(int percent, long bytesSent, long bytesToSend) uploadProgress = null);
ubyte[] uploadString(char[] address, char[] data, void delegate(int percent, long bytesSent, long bytesToSend) uploadProgress = null);

Uploads the specified string to the specified resource.

Parameters
Uri address
The URI of the resource to receive the string.
char[] data
The string to be uploaded.

Returns
A ubyte array containing the body of the response from the resource.

ubyte[] uploadFile(Uri address, char[] fileName, void delegate(int percent, long bytesSent, long bytesToSend) uploadProgress = null);
ubyte[] uploadFile(char[] address, char[] fileName, void delegate(int percent, long bytesSent, long bytesToSend) uploadProgress = null);

Uploads the specified local file to a resource with the specified URI.

Parameters
Uri address
The URI of the resource to receive the file. For example, ftp://localhost/samplefile.txt.
char[] fileName
The file to send to the resource. For example, "samplefile.txt".

Returns
A ubyte array containing the body of the response from the resource.

Examples
 import juno.net.core, std.stdio;

 void main() {
   writef("Enter the URI to upload to: ");
   string uriString = readln();

   writef("\nEnter the path of the file to upload: ");
   string fileName = readln();

   // Strip trailing '\n' on input.
   uriString = uriString[0 .. $-1];
   fileName = fileName[0 .. $-1];

   writefln("\nUploading %s to %s", fileName, uriString);

   // Upload the file to the URI.
   uploadFile(uriString, fileName);
 }