en:code:data:web
Differences
This shows you the differences between two versions of the page.
Previous revision | |||
— | en:code:data:web [2021/02/13 11:23] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Web ====== | ||
+ | This object allows you to download data. | ||
+ | ===== Functions ===== | ||
+ | |||
+ | ==== Web ==== | ||
+ | Constructor function. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | var myObject = new Web(eventsAndOptions); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - eventsAndOptions - (object) the events that can be called | ||
+ | * onFinished - ([[# | ||
+ | * onDownloadProgress - ([[# | ||
+ | * onError - ([[# | ||
+ | * file - ([[en: | ||
+ | |||
+ | === Example === | ||
+ | <code javascript> | ||
+ | var myObject = new Web(); | ||
+ | </ | ||
+ | <code javascript> | ||
+ | var myObject = new Web({ | ||
+ | onFinished: | ||
+ | { | ||
+ | Console.print(" | ||
+ | }, | ||
+ | file: " | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | ===== Methods ===== | ||
+ | |||
+ | ==== download ==== | ||
+ | Start downloading. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.download(url, | ||
+ | </ | ||
+ | <code javascript> | ||
+ | myObject.download(url); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - url - (string) the url of the resource to download | ||
+ | - 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, | ||
+ | To know when this is done use the [[# | ||
+ | |||
+ | ==== isDownloading ==== | ||
+ | Returns true if the data is still being downloaded. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.isDownloading(); | ||
+ | </ | ||
+ | |||
+ | === Returns === | ||
+ | * (boolean) true if the data is still being downloaded | ||
+ | |||
+ | ==== toImage ==== | ||
+ | Returns the downloaded data as an [[en: | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.toImage(); | ||
+ | </ | ||
+ | |||
+ | === Returns === | ||
+ | * ([[en: | ||
+ | |||
+ | === 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 === | ||
+ | <code javascript> | ||
+ | myObject.toText(encoding); | ||
+ | </ | ||
+ | <code javascript> | ||
+ | myObject.toText(); | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - encoding - ([[en: | ||
+ | |||
+ | === 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 [[en: | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.toRawData(); | ||
+ | </ | ||
+ | |||
+ | === Returns === | ||
+ | * ([[en: | ||
+ | |||
+ | === Notes === | ||
+ | You cannot use this method if you specified a destination file as no data is kept in memory. | ||
+ | |||
+ | ==== cancel ==== | ||
+ | Cancel the download. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.cancel(); | ||
+ | </ | ||
+ | |||
+ | === Returns === | ||
+ | * (Web) this Web | ||
+ | |||
+ | ===== Events ===== | ||
+ | |||
+ | ==== onFinished ==== | ||
+ | Called when the data has been downloaded. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.onFinished = function() {}; | ||
+ | </ | ||
+ | |||
+ | === Example === | ||
+ | <code javascript> | ||
+ | myObject.onFinished = function() | ||
+ | { | ||
+ | //Event action | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | ==== onDownloadProgress ==== | ||
+ | Called when the download progression has changed. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.onDownloadProgress = function(bytesReceived, | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - bytesReceived - (integer) received byte count | ||
+ | - bytesTotal - (integer) total byte count | ||
+ | |||
+ | === Example === | ||
+ | <code javascript> | ||
+ | myObject.onDownloadProgress = function(bytesReceived, | ||
+ | { | ||
+ | //Event action | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | ==== onError ==== | ||
+ | Called when an error occurs. | ||
+ | |||
+ | === Syntax === | ||
+ | <code javascript> | ||
+ | myObject.onError = function(errorText) {}; | ||
+ | </ | ||
+ | |||
+ | === Arguments === | ||
+ | - errorText - (string) a text describing the error | ||
+ | |||
+ | === Example === | ||
+ | <code javascript> | ||
+ | myObject.onError = function(errorText) | ||
+ | { | ||
+ | //Event action | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | ===== Enumerations ===== | ||
+ | |||
+ | ==== Method ==== | ||
+ | The download method. | ||
+ | |||
+ | === Values === | ||
+ | - Get: use " | ||
+ | - Post: use " |