Changes

Jump to navigation Jump to search
2,320 bytes added ,  13:51, 24 September 2019
no edit summary
This [[Module Library|XQuery Module]] contains functions related to file system operations, such as listing, reading, or writing files.
This module is based on the [http://expath.org/spec/file EXPath File Module].The following enhancements have not been added to the specification yet: {| class="wikitable"|- valign="top"! Function! Description|- valign="top"| [[#file:descendants|file:descendants]]| new function (since {{Version|9.3}})|- valign="top"| [[#file:is-absolute|file:is-absolute]]| new function|- valign="top"| [[#file:read-text|file:read-text]], [[#file:read-text-lines|file:read-text-lines]]| <code>$fallback</code> argument added|- valign="top"| [[#file:read-text-lines|file:read-text-lines]]| <code>$offset</code> and <code>$length</code> arguments added|- valign="top"| [[#file:resolve-path|file:resolve-path]]| <code>$base</code> argument added|}
=Conventions=
==file:list==
 
{| width='100%'
|-
| '''Summary'''
|Returns the full paths to all files and directories found in the specified {{Code|$dir}}.<br/>The inverse function is [[#file:parent|file:parent]]. The related function [[#file:list|file:list]] returns relative file paths.
|-
| '''Errors'''
|{{Error|not-found|#Errors}} the specified file does not exist.<br />{{Error|no-dir|#Errors}} the specified path does not point to a directory.<br />{{Error|io-error|#Errors}} the operation fails for some other reason.<br />
|}
 
==file:descendants==
 
{{Mark|Introduced with Version 9.3:}}
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|file:descendants|$dir as xs:string|xs:string*}}
|-
| '''Summary'''
|Returns the full paths to all files and directories found in the specified {{Code|$dir}} and its sub-directories.<br/>. The related function [[#file:list|file:list]] returns relative file paths.
|-
| '''Errors'''
|-
| '''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).
|}
|-
| '''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;).
| '''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).
|}
|-
| 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'''
|Creates the directory specified by {{Code|$dir}}, including all nonif it does not already exist. Non-existing parent directorieswill be created as well.<br />
|-
| '''Errors'''
|{{Error|exists|#Errors}} a file with the same path already specified target exists, but is no directory.<br />{{Error|io-error|#Errors}} the operation fails for some other reason.<br />
|}
==file:delete==
 
{| width='100%'
|-
==file:write==
 
{| width='100%'
|-
| '''Errors'''
|{{Error|no-dir|#Errors}} the parent of specified path is no directory.<br />{{Error|is-dir|#Errors}} the specified path is a directory.<br />{{Error|io-error|#Errors}} the operation fails for some other reason.<br />
|-
| '''Examples'''
|
* <code><nowiki>file:write('data.bin', xs:hexBinary('414243'))</nowiki></code> writes a hex representation to the specified file.
* <code><nowiki>file:write('data.bin', xs:hexBinary('414243'), map { 'method': 'basex')</nowiki></code> writes binary data to the specified file (see [[XQuery_Extensions#Serialization|Serialization]] for more details).
|}
==file:append==
 
{| width='100%'
|-
|}
==file:copy==
==file:copy==
{| width='100%'
|-
==file:move==
 
{| width='100%'
|-
==file:exists==
 
{| width='100%'
|-
==file:is-file==
 
{| width='100%'
|-
==file:last-modified==
 
{| width='100%'
|-
==file:size==
 
{| width='100%'
|-
==file:name==
 
{| width='100%'
|-
{| width='100%'
 
|-
| width='120' | '''Signatures'''
==file:path-to-native==
 
{| width='100%'
|-
==file:path-to-uri==
 
{| width='100%'
|-
==file:dir-separator==
 
{| width='100%'
|-
==file:path-separator==
 
{| width='100%'
|-
==file:line-separator==
 
{| width='100%'
|-
|-
| '''Summary'''
|Returns the current working directory. - This function returns the same result as the function call <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
* Added: [[#file:descendants|file:descendants]]
* 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