追加到gzip压缩的焦油存档 [英] Append to gzipped Tar-Archive

查看:158
本文介绍了追加到gzip压缩的焦油存档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个程序,生成一个压缩包,它获取COM $ P $由的zlib pssed。结果
每隔一定时间,相同的程序应该是一个新的文件添加到压缩包。

I've written a program, generating a tarball, which gets compressed by zlib.
At regular intervals, the same program is supposed to add a new file to the tarball.

根据定义,将压缩包需要空记录(512字节块)正常工作在它的结束,这已经显示了我的问题。

Per definition, the tarball needs empty records (512 Byte blocks) to work properly at it's end, which already shows my problem.

据文件 gzopen 无法在 R + 模式打开该文件,这意味着我不能简单地跳到的空记录开始的时候,我的附加文件信息,并与空记录再次密封。

According to documentation gzopen is unable to open the file in r+ mode, meaning I can't simply jump to the beginning of the empty records, append my file information and seal it again with empty records.

现在,我在我束手无策。细跟zlib的,附加的作品只要空记录并没有参与,但我需要他们为'完成'我的COM pressed包。

Right now, I'm at my wits end. Appending works fine with zlib, as long as the empty records are not involved, yet I need them to 'finalize' my compressed tarball.

任何想法?

是啊,这将是很好,如果我能避免DECOM pressing整个事情和/或分析整个压缩包。

Ah yes, it would be nice if I could avoid decompressing the whole thing and/or parsing the entire tarball.

我也开放供其他(preferably简单)文件格式我可以实现,而不是焦油。

I'm also open for other (preferably simple) file formats I could implement instead of tar.

推荐答案

在我看来这是不可能的TAR符合标准严格。我已经通过的zlib [1] 手动和的GNU tar [2] 文件规范。我没有找到任何信息,如何追加到TAR可以实现。所以我假设它有过度写空块来完成。

In my opinion this is not possible with TAR conforming to standard strictly. I have read through zlib[1] manual and GNU tar[2] file specification. I did not find any information how appending to TAR can be implemented. So I am assuming it has to be done by over-writing the empty blocks.

所以,我认为,同样,你可以用做 gzseek()。然而,你需要知道有多大的uncom pressed存档(尺寸),并设置偏移尺寸2 * 512
注意,既然的何处参数定义为在了lseek(2);不支持的值SEEK_END,这可能是很麻烦的 1 并不能打开文件进行读取,并在同一时间写,即对于反思的地方结束块。

So I assume, again, you can do it by using gzseek(). However, you would need to know how large is the uncompressed archive (size) and set offset to size-2*512. Note, that this might be cumbersome since "The whence parameter is defined as in lseek(2); the value SEEK_END is not supported."1 and you can't open file for reading and writing at the same time, i.e. for introspect where the end blocks are.

然而后,应该可以稍稍滥用TAR规格。在的GNU tar [2] 文档提到的东西的搞笑的:

However, it should be possible abusing TAR specs slightly. The GNU tar[2] docs mention something funny:


归档每个文件是由一个首标块,描述了文件,后面的零或更多的块,从而使该文件的内容psented重新$ P $。在归档文件的末尾有充满二进制零作为档案结尾的标记两个512字节的块。合理的制度应该在归档的结尾写这么档案结尾的盯防,但是不能假定读取压缩文件时这样的块存在。特别的GNU tar总是发出警告,如果不遇到它。

" Each file archived is represented by a header block which describes the file, followed by zero or more blocks which give the contents of the file. At the end of the archive file there are two 512-byte blocks filled with binary zeros as an end-of-file marker. A reasonable system should write such end-of-file marker at the end of an archive, but must not assume that such a block exists when reading an archive. In particular GNU tar always issues a warning if it does not encounter it. "

这意味着,你可以故意不写那些块。这是很容易,如果你写的压缩包COM pressor。然后你就可以在正常的追加模式下使用的zlib ,记住,西藏自治区DECOM pressor必须注意的的TAR文件

This means, you can deliberately not write those blocks. This is easy if you wrote the tarball compressor. Then you can use zlib in the normal append mode, remembering that the TAR decompressor must be aware of the "broken" TAR file.

[1] http://www.zlib.net/manual.html#Gzip
[2]
http://www.gnu.org/software/焦油/手动/ html_node / Standard.html#SEC182

这篇关于追加到gzip压缩的焦油存档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆