Implement EXPath Binary Module 4.0#6101
Conversation
Migration crosswalk:
|
eXist util: function |
EXPath bin: equivalent |
Notes |
|---|---|---|
util:binary-to-string($bin) |
bin:decode-string($bin) |
Both default to UTF-8 |
util:binary-to-string($bin, $enc) |
bin:decode-string($bin, $enc) |
Direct equivalent |
util:string-to-binary($str) |
bin:encode-string($str) |
Both default to UTF-8 |
util:string-to-binary($str, $enc) |
bin:encode-string($str, $enc) |
Direct equivalent |
util:base64-encode($str) |
string(bin:encode-string($str)) |
util: operates on strings (text→base64 text); bin: returns xs:base64Binary, so cast/serialize to get the base64 string representation |
util:base64-decode($str) |
bin:decode-string(xs:base64Binary($str)) |
util: accepts a base64-encoded string; bin: accepts xs:base64Binary, so cast the string first |
util:base64-encode-url-safe($str) |
bin:encode-string($str) => string() => translate("+/=", "-_") |
RFC 4648 §5 URL-safe encoding. See qt4cg/qtspecs#2381 for discussion of adding native support to a future spec. |
Note: util:binary-doc, util:binary-doc-available, util:is-binary-doc, and util:binary-doc-content-digest are database-level resource accessors with no EXPath Binary Module counterpart.
🤖 Co-authored with Claude Code
Adds a complete implementation of the EXPath Binary Module 4.0 specification (http://expath.org/ns/binary), providing 23 XQuery functions for binary data manipulation. Functions implemented: - Conversion: bin:hex, bin:bin, bin:octal, bin:to-octets, bin:from-octets - Basic: bin:length, bin:part, bin:join, bin:insert-before, bin:pad-left, bin:pad-right, bin:find - Text: bin:decode-string, bin:encode-string - Packing: bin:pack-double, bin:pack-float, bin:pack-integer, bin:unpack-double, bin:unpack-float, bin:unpack-integer, bin:unpack-unsigned-integer - Bitwise: bin:or, bin:xor, bin:and, bin:not, bin:shift The one function not implemented is bin:infer-encoding, which requires XQuery 4.0 record types for its return value. XQTS results: 574/574 tests pass (27/27 test sets, 0 failures). Closes eXist-db#6100 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
c94b63a to
6be0282
Compare
|
I am thinking if this should not rather be a installable package. |
|
[This response was co-authored with Claude Code. -Joe] @line-o Agreed — a standalone installable package is the right approach. We've already moved in this direction with five other EXPath/EXQuery modules:
All use a uniform convention: The EXPath Binary Module would follow the same pattern — extract from Happy to prepare this if you'd like. |
|
[This response was co-authored with Claude Code. -Joe] Following the community's suggestion, this module has been extracted into a standalone EXPath package: https://github.com/joewiz/exist-binary Same namespace ( This PR can be closed in favor of the standalone package approach. |
|
Closing in favor of the standalone package approach at https://github.com/joewiz/exist-binary. |
Summary
bin:infer-encodingis deferred (requires XQuery 4.0 record types)What Changed
New Files (8 source + 1 test)
BinaryModule.java— Module registration (http://expath.org/ns/binary, prefixbin)BinaryModuleErrorCode.java— 8 spec-defined error codesBinaryModuleHelper.java— Shared utilities (binary data extraction, creation, endianness)BinaryConversionFunctions.java—bin:hex,bin:bin,bin:octal,bin:to-octets,bin:from-octetsBinaryBasicFunctions.java—bin:length,bin:part,bin:join,bin:insert-before,bin:pad-left,bin:pad-right,bin:findBinaryTextFunctions.java—bin:decode-string,bin:encode-stringBinaryPackingFunctions.java—bin:pack-double,bin:pack-float,bin:pack-integer,bin:unpack-double,bin:unpack-float,bin:unpack-integer,bin:unpack-unsigned-integerBinaryBitwiseFunctions.java—bin:or,bin:xor,bin:and,bin:not,bin:shiftBinaryModuleTest.java— 74 JUnit testsModified Files
exist-distribution/src/main/config/conf.xml— Register moduleextensions/expath/src/test/resources-filtered/conf.xml— Register module for testsSpec Reference
XQTS Results
All QT4 binary module test sets pass with zero failures:
Note on XQTS Coverage
The XQTS results above were obtained using a development version of exist-xqts-runner with added support for XPath/XQuery 4.0 spec dependencies (
XP40,XQ40). Running the XQTS binary module test sets requires eXist-db/exist-xqts-runner#45.Test Plan
Closes #6100
🤖 Generated with Claude Code