Windows 上的文件串联及逆向操作

发布于 2024-12-11 20:23:34 字数 417 浏览 0 评论 0原文

我目前正在尝试找到一种方法来将多个文件(通常是目录中的所有文件(包括递归))连接到单个流中,以进行进一步处理。 TAR 看起来是一个明显的候选者,只是它在 Windows 中根本不是标准的,不幸的是,我能找到的所有版本(主要是 GNU TAR 的变体)都太大了(一旦包含 DLL 依赖项,就有数百 KB)。我需要一些更小的东西。

显然,标准 COPY 命令可以解决这个问题。例如,以下命令有效: COPY /B sourcefile1+sourcefile2 targetfile

但是,仍然有两个问题:我不知道如何将结果写入stdout(对于管道),更重要的是如何实现反向操作?

我需要一个小实用程序来完成这项串联工作,可以是 C 源代码、标准 Windows 命令,也可以是可分发的二进制文件。它不需要遵守 TAR 格式(尽管这样做也不是坏事)。显然连接应该是可逆的。

I'm currently trying to find a way to concatenate several files, typically all files from within a directory (recursive included) into a single stream, for further processing.
TAR looks like an obvious candidate, except that it is not at all standard in Windows, and unfortunately, all versions i could find (mostly variations of GNU TAR) are much too big (several hundreds of KB once included DLL dependencies). I need something much smaller.

Apparently, the standard COPY command could do the trick. For example the following command works:
COPY /B sourcefile1+sourcefile2 destinationfile

However, there are still 2 problems : I don't know how to write the result to stdout (for pipe), and even more importantly how to achieve the reverse operation ?

I need a small utility to do this concatenation job, either in C source code, a standard windows command, or as a distributable binary. It doesn't need to respect the TAR format (although it is not a bad thing if it does). And obviously the concatenation shall be reversible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苦妄 2024-12-18 20:23:34

我建议使用 7-zip。它有 portable 版本,可以很好地压缩(或只是复制而不压缩)所有文件递归子目录并将输出写入单个流(标准输出)。

它有“-so”(将数据写入标准输出)开关。例如,

7z x archive.gz -so > Doc.txt

将 archive.gz 存档解压缩到输出流,然后将该流重定向到 Doc.txt 文件。

7z a -tzip -so -r src\*.cpp src\*.h > archive.zip 

将 src 目录及其所有子目录中的所有 *.cpp- 和 *.h- 文件压缩到 7-Zip 标准输出流,并将该流写入 archive.zip 文件(删除“> archive.zip”并拦截输出你的程序)。

I suggest using 7-zip. It has portable version, can compress very good (or just copy without compression) all files recurse subdirectories and write output to single stream (stdout).

It has "-so" (write data to stdout) switch. For example,

7z x archive.gz -so > Doc.txt

decompresses archive.gz archive to output stream and then redirects that stream to Doc.txt file.

7z a -tzip -so -r src\*.cpp src\*.h > archive.zip 

compresses the all *.cpp- and *.h- files in src directory and all it subdirectories to the 7-Zip standard output stream and writes that stream to archive.zip file (remove "> archive.zip" and intercept output by your program).

没企图 2024-12-18 20:23:34

为什么不使用 ZIP(如果需要,可以禁用压缩)?它非常标准,并且支持内置于 Windows 中。请参阅在 Windows (XP/2003) 上创建 ZIP 文件在 C/C++ 中

纯串联是不可逆的,因为您不知道在哪里再次拆分它。因此,您应该使用块大小的目录,例如 ZIP 和 TAR 格式中存在的目录。

Why don't you use ZIP (disable compression if you want)? It's very standard, and support comes built into Windows. See Creating a ZIP file on Windows (XP/2003) in C/C++

Pure concatenation isn't reversible, because you can't know where to split it again. So you should use a directory of chunk sizes, such as exists in the ZIP and TAR formats.

来世叙缘 2024-12-18 20:23:34

好吧,Shelwien 几乎解决了这个问题。
他建议的 Tar 版本“足够精简”(~120KB),并且不需要外部 DLL 依赖项。
http://downloads.sourceforge.net/project/unxutils/unxutils/current /UnxUtils.zip

不幸的是,它也有一些自己的问题,例如不支持 Unicode 字符、解释转义序列(因此以 t 开头的目录名会触发 \t这被认为是一个表格),以及 Windows XP 下管道实现的潜在问题(尽管在最后一个程序中它可能来自其他程序)。
所以这是一个死胡同。

解决方案仍有待找到...

[编辑] Shelwien 刚刚通过创建“shar”提供了一个解决方案,这是一个更小、更高效的 tar 替代品,没有上述限制。这解决了这个问题。

Well, Shelwien's almost solved the issue.
The Tar version he proposes is "lean anough" (~120KB) and does not necessitate external DLL dependancies.
http://downloads.sourceforge.net/project/unxutils/unxutils/current/UnxUtils.zip

Unfortunately, it also has some problems of its own, such as no support for Unicode characters, interpreted escape sequence (so a directory name starting with t triggers a \t which is considered a tabulation), and a potential problem with pipe implementation under Windows XP (although on this last one it could come from the other program).
So that's a dead end.

A solution is still to be found...

[Edit] Shelwien just provided a solution by creating "shar", a tar replacement much smaller and much more efficient, without the limitations described above. This solve the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文