dlang 读取gz压缩文件

没找到打开gz压缩文件的标准库,暂时调用系统命令打开gz压缩文件(参考:https://dlang.org/phobos/std_process.html#.Redirect.stdoutToStderr)。

缺点是文件全部会读入内存处理,对于大文件不太友好。

 1 import std.stdio;
 2 import std.process;
 3 import std.string;
 4 
 5 void main(string[] args){
 6     string fileName = args[1];
 7     string command = "gzip -dc " ~ fileName ;
 8     auto dmd = executeShell(command);
 9     if(dmd.status != 0){
10         writeln("Compilation failed:\n", dmd.output);
11     }
12     else{
13         auto all=chomp(dmd.output).split("\n");
14             writeln(typeid(all));
15                 for(int i=0; i<all.length; i++){
16                 writeln(all[i]);
17         }
18     }
19 }

 

posted @ 2021-02-01 18:04  天使不设防  阅读(119)  评论(0编辑  收藏  举报