dba/files
library moduleR
Summary
Download file.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : files/file-download.xqm
Imports
This module is imported by 0 modules. It imports 1 modules.
Variables
None
Functions
4.1 dba:file-download
Arities: dba:file-download#1R
dba:file-download
(
$name
as
xs:string
)
as
item() +
- name
as
xs:string
name of file
item() +
binary data
Invokes 4 functions from 3 modules
- config:directory#0
- {http://basex.org/modules/web}response-header#2
- {http://expath.org/ns/file}read-binary#1
- {http://expath.org/ns/file}size#1
Invoked by 0 functions from 0 modules
Annotations
%rest:GET | () |
%rest:path | ('/dba/file/{$name}') |
Source ( 12 lines)
function dba:file-download(
$name as xs:string
) as item()+ {
let $path := config:directory() || $name
return (
web:response-header(
map { 'media-type': 'application/octet-stream' },
map { 'Content-Length': file:size($path) }
),
file:read-binary($path)
)
}
Namespaces
The following namespaces are defined:
Prefix | Uri |
---|---|
config | dba/config |
dba | dba/files 2 3 4 5 6 7 8 |
rest | http://exquery.org/ns/restxq |
Source Code
(:~
: Download file.
:
: @author Christian Grün, BaseX Team 2005-21, BSD License
:)
module namespace dba = 'dba/files';
import module namespace config = 'dba/config' at '../lib/config.xqm';
(:~
: Downloads a file.
: @param $name name of file
: @return binary data
:)
declare
%rest:GET
%rest:path('/dba/file/{$name}')
function dba:file-download(
$name as xs:string
) as item()+ {
let $path := config:directory() || $name
return (
web:response-header(
map { 'media-type': 'application/octet-stream' },
map { 'Content-Length': file:size($path) }
),
file:read-binary($path)
)
};