Changes

Jump to navigation Jump to search
100 bytes removed ,  16:20, 27 February 2020
no edit summary
The XQuery expression below serves as an example on how large files can be downloaded and written to a file with constant memory consumption:
<pre classsyntaxhighlight lang="brush:xquery">
file:write-binary('output.data', fetch:binary('http://files.basex.org/xml/xmark111mb.zip'))
</presyntaxhighlight>
If lazy items are serialized, they will be streamed as well.
==lazy:cache==
 
{{Mark|Updated with Version 9.1:}} [[#lazy:cache|lazy:cache]]: {{Code|$lazy}} argument added; support for sequences.
{| width='100%'
* data of lazy items will be retrieved and cached inside the item.
* non-lazy items, or lazy items with cached data, will simply be passed through.
* If {{Code|$lazy}} is set to {{Code|true()}}, caching will be deferred until the data is eventually requested. Streaming, however, will be disabled: Data will always be cached before an input a stream will be generatedis returned.
Caching is advisable if an item will be processed more than once, or if the data may not be available anymore at a later stage.
|-
| '''Example'''
|In the following example, a file will be deleted before its content is returned. To avoid a “file not found” error when serializing the result, the content must be cached:
<pre classsyntaxhighlight lang="brush:xquery">
let $file := 'data.txt'
let $text := lazy:cache(file:read-text($file))
return (file:delete($file), $text)
</presyntaxhighlight>
|}
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu