load. Loading file from disk or HTTP-server

^file::load[format;filename]
^file::load[
format;filename;download options]
^file::load[
format;filename;new filename]
^file::load[format;filename;new filename;download options]

Loads file from disk or HTTP-server.

Format defines format of loaded file and can be either text or binary. The two types differ in newline characters. For PC these characters are 0D 0A. If file is being loaded in format text, 0D will be deemed unnecessary and truncated. These characters will be added back to the file by method save.

Filename-name of file with path or file's URL on HTTP-server.

It should be kept in mind that if argument
new filename is specified, its value will be assigned to field name. This argument is especially useful in dealing with method mail:send to send a file with needed name.

Download options
-see "Working with HTTP-servers".

If a file was loaded from an HTTP-server, fields of HTTP-response headers can be accessed as fields of object of class
file.
Also there would be field tables, hash, keys of which are HTTP-response headers in upper case, and values are tables with sole column value, containing all values of HTTP-response fields of same name.
All incoming
cookies are stored in field cookies as a table with columns name, value, expires, max-age, domain, path, httponly and secure.   [3.4.2]

Example of downloading file from disk
$f[^file::load[binary;article.txt]]
File $f.name is $f.size in size and has the text:<br />
$f.text


Example of downloading file from HTTP-server
$file[^file::load[text;http://www.parser.ru/;
   $.timeout(5)
]]
Server software: $file.SERVER
<hr />
<pre>
$file.text
</pre>


Copyright © 1997–2017 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 22.10.2013