简体   繁体   English

如何在eXist-db和xQuery中的函数运行期间压缩二进制文件

[英]How to zip binary files during function’s run in eXist-db and xQuery

I have no problems with producing pdfs and offering them as response:stream-binary files for download. 我不会产生pdf并将其作为response:stream-binary提供问题response:stream-binary文件以供下载。 However, I have problems if I try to zip produced pdfs and do the same with zip. 但是,如果我尝试将生成的pdf压缩并用zip进行压缩,则会遇到问题。 It offers the zip result for download. 它提供了zip结果供下载。 The pdf is included but has no size (empty file). 包含pdf,但没有大小(空文件)。

let $pdf-binary :=
(
    if ($pdfQuality eq 'proof' and $template eq 'draft')
        then xslfo:render(transform:transform($doc, $stylesProof, ()), 'application/pdf', (), $proofConf)
    else if ($pdfQuality eq 'print' and $template eq 'draft')
        then xslfo:render(transform:transform($doc, $stylesPrint, ()), 'application/pdf', (), $printConf)
    else if ($pdfQuality eq 'print' and $template eq 'auc-geographica')
        then xslfo:render(transform:transform($doc, $stylesAUCGeographica, ()), 'application/pdf', (), $printConf)
    else ()
)
return
    if (not($zipAll))
        then response:stream-binary($pdf-binary, 'application/pdf', $name  || '.pdf')
    else if ($zipAll)
        then (
            let $entry := <entry name="{$name}.pdf" type="binary" method="store">{util:binary-doc($pdf-binary)}</entry>
            let $zip-file := compression:zip($entry, false())
            return
                response:stream-binary($zip-file, 'application/zip', 'test.zip')
        )
    else ()

Important is I don't want to store pdf results anywhere in the DB. 重要的是我不想将pdf结果存储在数据库中的任何位置。

Done. 做完了 It was better to slightly rearrange the project. 最好稍微重新安排项目。 I used the whole logic in the query calling the rendering function. 我在调用渲染函数的查询中使用了整个逻辑。 The working result is: 工作结果是:

...
let $zip as item() := 
    (
        let $entries as item()+ := 
            (
                for $article at $count in $doc/article//tei:TEI
                let $year as xs:string := $article//tei:date/string()
                let $issue as xs:string := $article//tei:biblScope/string()
                let $pdf as xs:base64Binary := fop:render-pdf($article, $template, $name, $pdfQuality)
                return
                    <entry name="{lower-case($name)}-{$year}-{$issue}-{$count}.pdf" type="binary" method="store">{$pdf}</entry>
            )
            return
                compression:zip($entries, false())
    )
return 
       response:stream-binary($zip, 'application/zip', $name  || '.zip')

I would be very happy if anyone could revise this solution. 如果有人可以修改此解决方案,我将非常高兴。 I have learned it is really great idea to use strong typing and don't rely on automatic conversions. 我了解到,使用强类型输入并且不依赖自动转换是一个好主意。 Without that this code does not work. 否则,该代码将无法正常工作。 Thanks a lot to the book about eXist-db, by Erik Siegel and Adam Retter, where I have seen a hint. 非常感谢Erik Siegel和Adam Retter撰写的有关eXist-db的书,在这里我看到了提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM