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

gru*_*ewa 2 ocaml

当我尝试使用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;;
Run Code Online (Sandbox Code Playgroud)

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

$ 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
Run Code Online (Sandbox Code Playgroud)

有谁知道什么是错的?

ivg*_*ivg 5

您的代码没有任何问题.它实际上是Tar_unix模块中的一个错误.该output函数不够健壮,End_of_file如果写入被截断,则会失败.我已经解决了这个问题,你的代码运行正常.有关更多信息,请参阅我的PR.

更新

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

opam update
opam upgrade
Run Code Online (Sandbox Code Playgroud)

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

opam show tar-format
Run Code Online (Sandbox Code Playgroud)

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

opam install 'tar-format>=0.5.1'
Run Code Online (Sandbox Code Playgroud)