0

我正在尝试通过 elisp 中的 XML-RPC 从文件(PNG 图像)传输二进制数据。这是自动将附件上传到 Confluence wiki 的一部分,特别是当前页面中使用的本地图像。这样做的代码是:

        ;; Open the file and get content
        (with-temp-buffer
          ;; file-name is the PNG file name, which is binary data
          (find-file (expand-file-name file-name current-dir))
          ;; Setup Confluence request alist
          (setq confl-req (list 
                           (cons "fileName" file-name)
                           (cons "contentType" mime-type)))
          ;; RPC call
          (setq confl-reply (cfln-rpc-execute 'confluence1.addAttachment
                                              page-id confl-req (buffer-substring-no-properties (point-min) (point-max))))

我的作品有问题(buffer-substring-no-properties (point-min) (point-max))。上传到 Confluence 的二进制数据在几个位置与 PNG 文件不匹配。我注意到附件中的字节0xe0 0x88被替换了。0xc8知道如何获取文件中包含的确切二进制数据吗?

谢谢, NMA

4

2 回答 2

3

您应该使用insert-file-contents-literally而不是find-file.

(insert-file-contents-literally FILENAME &optional VISIT BEG END
REPLACE)

Like `insert-file-contents', but only reads in the file literally.
A buffer may be modified in several ways after reading into the buffer,
to Emacs features such as format decoding, character code
conversion, `find-file-hook', automatic uncompression, etc.

This function ensures that none of these modifications will take place.
于 2012-08-16T20:11:55.457 回答
0

f-library 提供了符合@npostavs 答案的一站式解决方案: https ://github.com/rejeep/f.el

f-read-bytes

它用

insert-file-contents-literally

和...一起

buffer-substring-no-properties

负责编码和多字节处理....

于 2015-01-02T15:20:30.643 回答