Web Downloads The Download operation has been written by Thomas Breuer, incorporating a number of suggestions from Max Horn, for version 0.77 of Utils. It implements downloading a file from within &GAP;. It can use the IO or curlInterface packages, or wget or curl, if installed, and it can be extended with other download methods quite easily. It is envisaged that, once other packages have started to use it, and any problems have been addressed, that the functions will be transferred to the main &GAP; library.
Functions for downloading files from the web This function downloads the file with the web address url, which must be a string.

The result is a record which has at least the component success, with value true if the download was successful and false otherwise. In the former case, the component result is bound, whose value is a string that contains the contents of the downloaded file. In the latter case, the component error is bound, whose value is a string that describes the problem.

The function calls the methods stored in the global list Download_Methods until one of them is successful. Currently there are methods based on the &GAP; functions and , and methods based on the external programs wget and curl.

An optional record opt can be given. The following components are supported.

maxTime If this component is bound then its value must be a nonnegative integer n, meaning that the function gives up after n seconds.

A zero value of n means that no timeout is set, the method will never give up in this case.

The default for n is given by the value of the user preference DownloadMaxTime (see ). target If this component is bound then its value must be a string that is a local filename, and the function writes the downloaded contents to this file; the returned record does not have a result component in this case. verifyCert If this component is bound and has the value false then those download methods that are based on curl or wget will omit the check of the server's certificate.

The same effect is achieved for all calls by setting the user preference DownloadVerifyCertificate (see ) to false and omitting the verifyCert component from opt.

gap> url:= "https://www.gap-system.org/index.html";; gap> res1:= Download( url );; gap> res1.success; true gap> IsBound( res1.result ) and IsString( res1.result ); true gap> res2:= Download( Concatenation( url, "xxx" ) );; gap> res2.success; false gap> IsBound( res2.error ) and IsString( res2.error ); true
User preference DownloadVerifyCertificate DownloadVerifyCertificate The value true (the default) means that the server's certificate is checked in calls of , such that nothing gets downloaded if the certificate is invalid.

If the value is false then download methods are supposed to omit the check of the server's certificate (this may not be supported by all download methods).

One can set the value of the preference to be val via , by calling SetUserPreference( "utils", "DownloadVerifyCertificate", val ), and access the current value via , by calling UserPreference( "utils", "DownloadVerifyCertificate" ).

We recommend leaving this preference at its default value true. Sometimes it can be necessary to change it, e.g. to work around issues with old operating systems which may not be able to correctly verify new certificates. In general it is better to update such a system, but if that is not an option, then disabling certificate checks may be a good last resort. User preference DownloadMaxTime DownloadMaxTime The value 0 (the default) means that no timeout is set in calls of . If the value is a positive integer n then those download methods that support a timeout will give up after n seconds.

One can set the value of the preference to be val via , by calling SetUserPreference( "utils", "DownloadMaxTime", val ), and access the current value via , by calling UserPreference( "utils", "DownloadMaxTime" ).