User Tools

Site Tools


en:code:data:web

Web

This object allows you to download data.

Functions

Web

Constructor function.

Syntax

var myObject = new Web(eventsAndOptions);

Arguments

  1. eventsAndOptions - (object) the events that can be called
    • onFinished - (onFinished) called when the data has been downloaded
    • onDownloadProgress - (onDownloadProgress) called when the download progresses
    • onError - (onError) called when an error has occured
    • file - (File or string) the file or filename to use as a destination for the downloaded data, if this is not set the data will be stored into RAM

Example

var myObject = new Web();
var myObject = new Web({
	onFinished: function()
	{
		Console.print("Finished!");
	},
	file: "myFile.txt"
});

Methods

download

Start downloading.

Syntax

myObject.download(url, options);
myObject.download(url);

Arguments

  1. url - (string) the url of the resource to download
  2. options - (object) options
    • rawHeaders - (object) raw headers to set
    • method - (Method) the method to use (get or post)
    • postData - (object) post data to send
    • query - (object) query items
    • user - (string) the username to use if asked
    • password - (string) the password to use if asked

Returns

  • (Web) this Web

Exceptions

  • (OpenFileError) unable to open the destination file

Notes

This method is asynchronous, this means that it will return before the data is downloaded. To know when this is done use the onFinished event or the isDownloading method.

isDownloading

Returns true if the data is still being downloaded.

Syntax

myObject.isDownloading();

Returns

  • (boolean) true if the data is still being downloaded

toImage

Returns the downloaded data as an Image.

Syntax

myObject.toImage();

Returns

Notes

You cannot use this method if you specified a destination file as no data is kept in memory.

toText

Returns the downloaded data as text.

Syntax

myObject.toText(encoding);
myObject.toText();

Arguments

  1. encoding - (Encoding) the encoding to use

Returns

  • (string) the text

Notes

You cannot use this method if you specified a destination file as no data is kept in memory.

toRawData

Returns the downloaded data as RawData.

Syntax

myObject.toRawData();

Returns

Notes

You cannot use this method if you specified a destination file as no data is kept in memory.

cancel

Cancel the download.

Syntax

myObject.cancel();

Returns

  • (Web) this Web

Events

onFinished

Called when the data has been downloaded.

Syntax

myObject.onFinished = function() {};

Example

myObject.onFinished = function()
{
	//Event action
};

onDownloadProgress

Called when the download progression has changed.

Syntax

myObject.onDownloadProgress = function(bytesReceived, bytesTotal) {};

Arguments

  1. bytesReceived - (integer) received byte count
  2. bytesTotal - (integer) total byte count

Example

myObject.onDownloadProgress = function(bytesReceived, bytesTotal)
{
	//Event action
};

onError

Called when an error occurs.

Syntax

myObject.onError = function(errorText) {};

Arguments

  1. errorText - (string) a text describing the error

Example

myObject.onError = function(errorText)
{
	//Event action
};

Enumerations

Method

The download method.

Values

  1. Get: use "get" method (default)
  2. Post: use "post" method
en/code/data/web.txt · Last modified: 2016/10/09 11:10 (external edit)