问题描述
这是链接的问题的延续.
在我看来, std/archive/tar.ts
模块的当前实现允许对每个文件进行读写,而不能对整个目录进行读写.
It seems to me, that current implementation of the std/archive/tar.ts
module only allows reads and writes per file and not for whole directories.
到目前为止,我的参考文献是测试文件,仅显示了案例单个文件处理.但是,例如,如果给出了包含多个文件的目录./my-dir/
和tar归档文件./test.tar
怎么办?
So far, my reference source are the test files, which only show case single file processing. But what if, for example, a directory ./my-dir/
with multiple files and a tar archive ./test.tar
is given.
然后我该如何利用 append
, extract
&公司能否有效地将./my-dir/
写入./test.tar
存档并从中读取所有文件内容?
How can I then utilize append
, extract
& Co. to efficiently write ./my-dir/
to ./test.tar
archive and read all file contents back from it?
推荐答案
您可以使用std/fs/walk
import { walk, walkSync } from "https://deno.land/std/fs/walk.ts";
import { Tar } from "https://deno.land/std/std/archive/tar.ts";
// Async
const tar = new Tar();
for await (const entry of walk("./dir-to-archive")) {
if (!entry.isFile) {
continue;
}
await tar.append(entry.path, {
filePath: entry.path,
});
}
const writer = await Deno.open("./test.tar", { write: true, create: true });
await Deno.copy(tar.getReader(), writer);
Untar
文件夹/多个文件的实现已损坏.
Untar
implementation for folders/multiple files is broken.
这篇关于使用tar归档读取和写入整个目录(标准库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!