我用的是 在Domino AppDev Pack 1.0.4的文档中作为例子提出的代码。 唯一的区别是读取一个文本文件(body.txt)作为缓冲区,这个文件只包含简单的长文本(40Ko)。
当它被执行时,文档在数据库中被创建,其余代码没有返回错误.但最后,富文本字段没有被添加到文档中.这里返回的是响应。
response: {"fields":[{"fieldName":"Body","unid":"8EA69129BEECA6DEC1258554002F5DCD","error":{"name":"ProtonError","code":65577,"id":"RICH_TEXT_STREAM_CORRUPT"}}]}
我的目标是在一个富文本字段中写入很长的文本(超过64Ko)。我在例子中使用一个文本文件作为缓冲区,但它可以是后来的东西,如 const buffer = Buffer.from ('very long text ...')
这是正确的方法还是必须用不同的方法?
我使用的是Windows系统,装有IBM Domino (r) Server (64 Bit), Release 10.0.1FP4和AppDevPack 1.0.4。
预先感谢您的帮助
下面是代码。
const write = async (database) => {
let writable;
let result;
try {
// Create a document with subject write-example-1 to hold rich text
const unid = await database.createDocument({
document: {
Form: 'RichDiscussion',
Title: 'write-example-1',
},
});
writable = await database.bulkCreateRichTextStream({});
result = await new Promise((resolve, reject) => {
// Set up event handlers.
// Reject the Promise if there is a connection-level error.
writable.on('error', (e) => {
reject(e);
});
// Return the response from writing when resolving the Promise.
writable.on('response', (response) => {
console.log("response: " + JSON.stringify(response));
resolve(response);
});
// Indicates which document and item name to use.
writable.field({ unid, fieldName: 'Body' });
let offset = 0;
// Assume for purposes of this example that we buffer the entire file.
const buffer = fs.readFileSync('/driver/body.txt');
// When writing large amounts of data, it is necessary to
// wait for the client-side to complete the previous write
// before writing more data.
const writeData = () => {
let draining = true;
while (offset < buffer.length && draining) {
const remainingBytes = buffer.length - offset;
let chunkSize = 16 * 1024;
if (remainingBytes < chunkSize) {
chunkSize = remainingBytes;
}
draining = writable.write(buffer.slice(offset, offset + chunkSize));
offset += chunkSize;
}
if (offset < buffer.length) {
// Buffer is not draining. Whenever the drain event is emitted
// call this function again to write more data.
writable.once('drain', writeData);
}
};
writeData();
writable = undefined;
});
} catch (e) {
console.log(`Unexpected exception ${e.message}`);
} finally {
if (writable) {
writable.end();
}
}
return result;
};
从appdev包1.0.4开始,富文本流接受写入有效的富文本cd格式的数据,采用LMBCS字符集。 我们目前正在开发一个库来帮助你向流中写入有效的富文本数据。
我很想听到更多关于你的用例,我们很高兴你已经在摸索这个功能了! 如果你能加入openntf slack频道,我通常会在那里闲逛。