Difference between revisions of "Lazy Module"
Line 1: | Line 1: | ||
This [[Module Library|XQuery Module]] contains functions for handling ''streamable'' items. | This [[Module Library|XQuery Module]] contains functions for handling ''streamable'' items. | ||
− | In contrast to conventional XQuery items, streamable items may take up much less space, because they only contain a reference to the actual data. The data will only be retrieved if it is required, | + | In contrast to conventional XQuery items, streamable items may take up much less space, because they only contain a reference to the actual data. The data itself will only be retrieved if it is required by another expression, or if an item is serialized. Serialization of streamable items takes constant space. |
− | + | The following BaseX functions return streamable items: | |
* <code>[[Database Module#db:retrieve|db:retrieve]]</code> | * <code>[[Database Module#db:retrieve|db:retrieve]]</code> | ||
Line 11: | Line 11: | ||
* <code>[[File Module#file:read-text|file:read-text]]</code> | * <code>[[File Module#file:read-text|file:read-text]]</code> | ||
− | The following functions are | + | Some functions are capable of consuming items in a ''streamable'' fashion: data will never be cached, but instead passed on to another target (file, the calling expression, etc.). The following streaming functions are currently available: |
* <code>[[Conversion Module#convert:binary-to-bytes|convert:binary-to-bytes]]</code> | * <code>[[Conversion Module#convert:binary-to-bytes|convert:binary-to-bytes]]</code> | ||
Line 17: | Line 17: | ||
* <code>[[Fetch Module#file:write-text|file:write-text]]</code> | * <code>[[Fetch Module#file:write-text|file:write-text]]</code> | ||
* <code>[[File Module#file:write-binary|file:write-binary]]</code> | * <code>[[File Module#file:write-binary|file:write-binary]]</code> | ||
+ | |||
+ | The exemplary XQuery expression below demonstrates how large files can be downloaded and written to a file with constant memory consumption: | ||
+ | |||
+ | <pre class="brush:xquery"> | ||
+ | file:write-binary('output.data', fetch:binary('http://files.basex.org/xml/xmark111mb.zip')) | ||
+ | </pre> | ||
=Conventions= | =Conventions= |
Revision as of 15:20, 12 March 2013
This XQuery Module contains functions for handling streamable items.
In contrast to conventional XQuery items, streamable items may take up much less space, because they only contain a reference to the actual data. The data itself will only be retrieved if it is required by another expression, or if an item is serialized. Serialization of streamable items takes constant space.
The following BaseX functions return streamable items:
Some functions are capable of consuming items in a streamable fashion: data will never be cached, but instead passed on to another target (file, the calling expression, etc.). The following streaming functions are currently available:
The exemplary XQuery expression below demonstrates how large files can be downloaded and written to a file with constant memory consumption:
file:write-binary('output.data', fetch:binary('http://files.basex.org/xml/xmark111mb.zip'))
Conventions
All functions in this module are assigned to the http://basex.org/modules/stream
namespace, which is statically bound to the stream
prefix.
All errors are assigned to the http://basex.org/errors
namespace, which is statically bound to the bxerr
prefix.
Functions
stream:materialize
Signatures | stream:materialize($item as item()) as item()
|
Summary | Returns a materialized instance of the specified $item .If an item is streamable, its content will be retrieved, and a new item containing its data will be returned. Other, non-streamable items will simply be returned. |
stream:is-streamable
Signatures | stream:is-streamable($item as item()) as item()
|
Summary | Checks if the specified $item is streamable.
|
Changelog
This module was introduced with Version 7.7.