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

查看:34
本文介绍了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天全站免登陆