Emacs 在elisp中读取二进制数据

Emacs 在elisp中读取二进制数据,emacs,elisp,Emacs,Elisp,我正在尝试通过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-fi

我正在尝试通过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))))
我对工件
(缓冲子串无属性(最小点)(最大点))
有问题。上载到Confluence的二进制数据在两个位置与PNG文件不匹配。我注意到附加文件中的字节
0xe0 0x88
替换为
0xc8
。知道如何获得文件中包含的确切二进制数据吗

谢谢,
NMA

您应该使用
按字面意思插入文件内容
,而不是
查找文件

(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.

您应该使用
插入文件内容,而不是
查找文件

(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.

f-library提供了一站式解决方案,该解决方案与@npostavs答案一致:

它使用

insert-file-contents-literally
连同

buffer-substring-no-properties

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

f-library提供了一个一站式解决方案,该解决方案与@npostavs answer一行一致:

它使用

insert-file-contents-literally
连同

buffer-substring-no-properties

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

这非常有效!在此之后我可以使用(缓冲字符串)吗?我不想返回文本属性。@NarendraAcharya可能没有文本属性,但使用
缓冲区子字符串no properties更安全,这非常有效!在此之后我可以使用(缓冲字符串)吗?我不希望返回文本属性。@NarendraAcharya可能没有文本属性,但使用
缓冲区子字符串no properties更安全