我正在尝试在 Raku 中逐行读取一个巨大的 gz 文件。
我正在尝试做这样的事情
my $file = 'huge_file.gz';
for $file.IO.lines -> $line {
say $line;
}
但这给出了我的 UTF-8 格式错误的错误。我看不到如何让它从帮助页面读取 gzip 压缩的材料https://docs.raku.org/language/unicode#UTF8-C8 https://docs.raku.org/language/unicode#UTF8-C8 or https://docs.raku.org/language/io https://docs.raku.org/language/io
我想要完成与 Perl5 中相同的事情:http://blog-en.openalfa.com/how-to-read-and-write-compressed-files-in-perl http://blog-en.openalfa.com/how-to-read-and-write-compressed-files-in-perl
如何在 Raku 中逐行读取 gz 文件?
thanks
我建议使用该模块Compress::Zlib
以此目的。您可以找到github 上的自述文件和代码 https://github.com/retupmoca/P6-Compress-Zlib/并安装它zef install Compress::Zlib
.
此示例取自标题为“wrap”的 3 号测试文件:
use Test;
use Compress::Zlib;
gzspurt("t/compressed.gz", "this\nis\na\ntest");
my $wrap = zwrap(open("t/compressed.gz"), :gzip);
is $wrap.get, "this\n", 'first line roundtrips';
is $wrap.get, "is\n", 'second line roundtrips';
is $wrap.get, "a\n", 'third line roundtrips';
is $wrap.get, "test", 'fourth line roundtrips';
这可能是获得您想要的东西的最简单方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)