D: how to extract data from archive?

試著忘記壹切 提交于 2019-12-11 02:18:04

问题


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);
    }
}

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


回答1:


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);
    }
}


来源:https://stackoverflow.com/questions/29373470/d-how-to-extract-data-from-archive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!