0

我使用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"}}]}

我的目标是在富文本字段中编写很长的文本(超过 64 Ko)。我在示例中为缓冲区使用了一个文本文件,但稍后可能会像const buffer = Buffer.from ('very long text ...')

这是正确的方法还是必须以不同的方式完成?

我正在使用带有 IBM Domino (r) Server(64 位)、Release 10.0.1FP4 和 AppDevPack 1.0.4 的 Windows 系统。

预先感谢您的帮助

这是代码:

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;
};
4

1 回答 1

1

从 appdev pack 1.0.4 开始,富文本流接受以 LMBCS 字符集写入有效富文本 cd 格式的数据。我们目前正在开发一个库来帮助您将有效的富文本数据写入流。

我很想听到更多关于您的用例的信息,我们很高兴您已经在探索该功能!如果你能加入 openntf slack 频道,我通常会在那里闲逛。

于 2020-04-24T14:33:41.407 回答