菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
461
0

dlang 读取gz压缩文件

原创
05/13 14:22
阅读数 96416

没找到打开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 }

 

相关热门文章

发表评论

0/200
461 点赞
0 评论
收藏
为你推荐 换一批