Open
Description
In some circumstances, ResultProvider.result()
returns a Buffer
object for a text node. This does not seem to be documented, and it is not clear how to handle them (e.g. which encoding to use.)
Neither ResultProvider.result()
nor DatabaseClient.eval()
documents this.
In order to replicate this, create 2 text documents in a database:
/test.txt
, with the following content:Hello, world!
/hello.xqy
, with the following content:'Hello, world!'
If you execute the following script:
"use strict";
const ml = require('marklogic');
async function main(client)
{
const res = client.eval(`cts.doc('/hello.xqy')`);
console.dir(await res.result());
client.release();
}
main(ml.createDatabaseClient({
host: 'localhost',
user: 'admin',
password: 'admin',
port: 8000,
authType: 'DIGEST',
database: 'Documents',
}));
The output is the following:
[
{
format: 'text',
datatype: 'node()',
value: Buffer(16) [Uint8Array] [
39, 72, 101, 108, 108,
111, 44, 32, 119, 111,
114, 108, 100, 33, 39,
10
]
}
]
Is this intentional? Is there a switch to enable/disable this behaviour? How are we supposed to deal with it? (using .toString()
?, with which encoding?)