spf13 / afero

A FileSystem Abstraction System for Go
Apache License 2.0
5.8k stars 498 forks source link

How can I unzip a file inside of a afero fs #363

Open schuster-rainer opened 2 years ago

schuster-rainer commented 2 years ago

Is it possible to unzip an archive that has been written to the afero fs? All my services are using the afero.Fs interface for IO.

I have a Downloader that stores a zip file and now I'm implementing an unzipper that takes an afero.Fs (where the file is stored) and I want to unzip the file inside the afero.Fs. In the zipfs example, an afero.fs is created based on zip.OpenReader. that uses the os package to open the zip file. But I want to open a zipfile within an afero fs. Is there support for it that I don't see? I just don't get it how to do it.

schuster-rainer commented 2 years ago

I was too fast opening this ticket.

    fileInfo, err := u.appFS.Stat(source)
    if err != nil {
        return err
    }
    file, err := u.appFS.OpenFile(source, os.O_RDONLY, os.FileMode(0644))
    if err != nil {
        return err
    }

    reader, err := zip.NewReader(file, fileInfo.Size())
    if err != nil {
        return err
    }
jxsl13 commented 2 years ago

@schuster-rainer close this issue?