Changes

Jump to navigation Jump to search
739 bytes added ,  14:09, 23 March 2018
For serialization parameters, the <code><nowiki>http://www.w3.org/2010/xslt-xquery-serialization</nowiki></code> namespace is used, which is statically bound to the {{Code|output}} prefix.<br/>
Returned strings that refer to existing directories are suffixed with a directory separator. The error <code>[[#Errors|invalid-path]]</code> is raised if a path is invalid. ==File Paths== * All file paths are resolved against the ''current working directory'' (the directory from which BaseX or, more generally, the Java Virtual Machine, was started). This directory can be retrieved via [[#file:base-dir|file:base-dir]]. * A path can be specified as local filesystem path or as file URI. * Returned strings that refer to existing directories are suffixed with a directory separator.
=Read Operations=
|-
| '''Summary'''
|Reads the binary content of the file specified by {{Code|$path}} and returns it as [[Streaming Lazy Module|streamablelazy]] {{Code|xs:base64Binary}}item.<br />The optional parameters {{Code|$offset}} and {{Code|$length}} can be used to read chunks of a file.
|-
| '''Errors'''
| '''Examples'''
|
* <code><nowiki>streamlazy:materializecache(file:read-binary("config.data"))</nowiki></code> returns a materialized representation of enforces the streamable resultfile access (otherwise, it will be delayed until requested first).
|}
==file:read-text==
 
{{Mark|Updated with Version 8.5}}: <code>$fallback</code> argument added.
{| width='100%'
|-
| '''Summary'''
|Reads the textual contents of the file specified by {{Code|$path}} and returns it as [[Streaming Lazy Module|streamablelazy]] {{Code|xs:string}}item:
* The UTF-8 default encoding can be overwritten with the optional {{Code|$encoding}} argument.
* By default, invalid characters will be rejected. If {{Code|$fallback}} is set to true, these characters will be replaced with the Unicode replacement character <code>FFFD</code> (&#xFFFD;).
|-
| '''Errors'''
|{{Error|not-found|#Errors}} the specified file does not exist.<br />{{Error|is-dir|#Errors}} the specified path is a directory.<br />{{Error|unknown-encoding|#Errors}} the specified encoding is not supported, or unknown.<br />{{Error|io-error|#Errors}} the operation fails for some other reason. Invalid XML characters will be ignored if the <code>[[Options#CHECKSTRINGS|CHECKSTRINGS]]</code> option is turned off.<br />
|-
| '''Examples'''
|
* <code><nowiki>streamlazy:materializecache(file:read-text("configids.txt"))</nowiki></code> returns a materialized representation of enforces the streamable resultfile access (otherwise, it will be delayed until requested first).
|}
==file:read-text-lines==
{{Mark|Updated with Version 89.50:}}[[#file:read-text-lines|file:read-text-lines]]: <code>$fallbackoffset</code> and <code>$length</code> argument arguments added.
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|file:read-text-lines|$path as xs:string|xs:string}}<br />{{Func|file:read-text-lines|$path as xs:string, $encoding as xs:string|xs:string*}}<br />{{Func|file:read-text-lines|$path as xs:string, $encoding as xs:string, $fallback as xs:boolean|xs:string*}}<br />{{Func|file:read-text-lines|$path as xs:string, $encoding as xs:string, $fallback as xs:boolean, $offset as xs:integer|xs:string*}}<br />{{Func|file:read-text-lines|$path as xs:string, $encoding as xs:string, $fallback as xs:boolean, $offset as xs:integer, $length as xs:integer|xs:string*}}<br />
|-
| '''Summary'''
* The UTF-8 default encoding can be overwritten with the optional {{Code|$encoding}} argument.
* By default, invalid characters will be rejected. If {{Code|$fallback}} is set to true, these characters will be replaced with the Unicode replacement character <code>FFFD</code> (&#xFFFD;).
The lines to be read can be restricted with the optional parameters {{Code|$offset}} and {{Code|$length}}.
|-
| '''Errors'''
|-
| '''Summary'''
|Returns the current working directory. - This function returns the same result as the function call {{Code|<code>file:resolve-path(''"")}}</code><br />
|}
|Description
|-
|{{Code|not-foundexists}}|A specified file with the same path does not existalready exists.
|-
|{{Code|invalid-path}}
|A specified path is invalid.
|-
|{{Code|exists}}|A file with the same path already exists.|-|{{Code|noio-direrror}}|The specified path does not point operation fails for some other reason specific to a directorythe operating system.
|-
|{{Code|is-dir}}
|The specified path is relative (and must be absolute).
|-
|{{Code|unknownno-encodingdir}}|The specified encoding is path does not supported, or unknownpoint to a directory.|-|{{Code|not-found}}|A specified path does not exist.
|-
|{{Code|out-of-range}}
|The specified offset or length is negative, or the chosen values would exceed the file bounds.
|-
|{{Code|iounknown-errorencoding}}|The operation fails for some other reason specific to the operating systemspecified encoding is not supported, or unknown.
|}
=Changelog=
 
;Version 9.0
* Updated: [[#file:read-text-lines|file:read-text-lines]]: <code>$offset</code> and <code>$length</code> arguments added.
;Version 8.5
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu