Skip to content

Latest commit

 

History

History
76 lines (50 loc) · 2.3 KB

File metadata and controls

76 lines (50 loc) · 2.3 KB

exist-binary

EXPath Binary Module 4.0 for eXist-db — binary data manipulation functions.

This package implements the EXPath Binary Module 4.0 specification as a standalone XAR package for eXist-db.

Functions

Section Functions
Conversions bin:hex, bin:bin, bin:octal, bin:to-octets, bin:from-octets
Basic Operations bin:length, bin:part, bin:join, bin:insert-before, bin:pad-left, bin:pad-right, bin:find
Text Encoding bin:decode-string, bin:encode-string
Numeric Packing bin:pack-double, bin:pack-float, bin:pack-integer, bin:unpack-double, bin:unpack-float, bin:unpack-integer, bin:unpack-unsigned-integer
Bitwise Operations bin:or, bin:xor, bin:and, bin:not, bin:shift

Requirements

  • eXist-db 6.0.0 or later

Installation

From a GitHub release:

xst package install https://github.com/joewiz/exist-binary/releases/download/v0.9.0-SNAPSHOT/exist-binary-0.9.0-SNAPSHOT.xar

From a local build:

mvn package -DskipTests
xst package install target/exist-binary-0.9.0-SNAPSHOT.xar

Usage

import module namespace bin = "http://expath.org/ns/binary";

(: Convert hex string to binary :)
let $data := bin:hex("DEADBEEF")

(: Get length in octets :)
let $len := bin:length($data)  (: 4 :)

(: Extract a part :)
let $part := bin:part($data, 1, 2)  (: bytes at positions 1-2 :)

(: Encode/decode strings :)
let $encoded := bin:encode-string("Hello, World!")
let $decoded := bin:decode-string($encoded)  (: "Hello, World!" :)

(: Pack/unpack numbers :)
let $packed := bin:pack-double(3.14)
let $value := bin:unpack-double($packed, 0)  (: 3.14 :)

return $decoded

XQTS Compliance

96% (183/190) of EXPath Binary Module test cases pass in the QT4 XQTS test suite.

Migration from PR #6101

If you previously used the in-tree Binary Module from eXist-db PR #6101, this standalone XAR is a drop-in replacement. The namespace (http://expath.org/ns/binary) and function signatures are identical.

To migrate:

  1. Remove the <module uri="http://expath.org/ns/binary" .../> line from your conf.xml (if present)
  2. Install this XAR package
  3. No changes needed in your XQuery code

License

LGPL 2.1 — same as eXist-db.