gpt4 book ai didi

ocaml - 使用 *ocaml_tar* 创建 TAR 文件时出现 End_of_file 异常

转载 作者:行者123 更新时间:2023-12-02 20:35:52 26 4
gpt4 key购买 nike

当我尝试使用 ocaml_tar 库创建 TAR 文件时,出现 End_of_file 异常。

我的代码...

#require "tar";;
#require "tar.unix";;
let f = Unix.openfile "test.tar" [ Unix.O_RDWR; Unix.O_CREAT ] 0o600;;
Tar_unix.Archive.create ["write_ex.ml"] f;;
Unix.close f;;

...产生以下堆栈跟踪:

$ utop write_ex.ml
Exception: End_of_file.
Raised at file "lib/tar.ml", line 549, characters 36-47
Called from file "lib/tar.ml", line 460, characters 4-11
Called from file "stream.ml", line 149, characters 33-38
Called from file "lib/tar.ml", line 578, characters 6-28
Called from file "toplevel/toploop.ml", line 180, characters 17-56

有人知道这是怎么回事吗?

最佳答案

你的代码没有任何问题。它实际上是 Tar_unix 模块中的一个错误。 output 函数不够健壮,如果写入被截断,则会失败并出现 End_of_file 异常。我已经解决了这个问题,并且您的代码工作正常。看我的PR了解更多信息。

更新

PR 已合并,较新的 (0.5.1) 版本已发布到 opam。升级到最新版本:

opam update
opam upgrade

通过查询 opam 确保安装了最新 (>= 0.5.1) 版本

opam show tar-format

如果它仍然是旧的,则强制 opam 安装最新的:

opam install 'tar-format>=0.5.1'

关于ocaml - 使用 *ocaml_tar* 创建 TAR 文件时出现 End_of_file 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39201064/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com