D:如何从存档中提取数据? [英] D: how to extract data from archive?

查看:95
本文介绍了D:如何从存档中提取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有非常简单的代码,应该从存档中提取数据:

I have very simple code that should extract data from archive:

import std.stdio;
import std.string;
import std.file;
import std.algorithm;
import std.zip;

void main()
{
    string ar = `D:\ftp\s2-imfset_2015\IFPET-150101.zip`;
    auto zip = new ZipArchive(ar.read);
    foreach(ArchiveMember am; zip.directory)
    {
        writeln(am.expandedData);
    }
}

(感谢您解释each和映射difference).但是,当我运行它时,它将在控制台上显示[].

(thanks for explaining about each and map difference). But when I run it it's print [] on console.

推荐答案

您需要在扩展数据可用之前调用zip.expand(am). 您还可以在扩展存档成员之前获取其名称和大小.

You need to call zip.expand(am) before the expanded data is available. You can also get the name and size of an archive member before expanding it.

import std.stdio;
import std.string;
import std.file;
import std.algorithm;
import std.zip;

void main()
{
    string ar = `D:\ftp\s2-imfset_2015\IFPET-150101.zip`;
    auto zip = new ZipArchive(ar.read);
    foreach(name, am; zip.directory)
    {
        if(!am.expandedSize) continue; // ignore empty files
        zip.expand(am);
        writeln(am.expandedData);
    }
}

这篇关于D:如何从存档中提取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆