afero icon indicating copy to clipboard operation
afero copied to clipboard

How can I unzip a file inside of a afero fs

Open schuster-rainer opened this issue 2 years ago • 2 comments

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 avatar Jun 20 '22 10:06 schuster-rainer

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
	}

schuster-rainer avatar Jun 20 '22 10:06 schuster-rainer

@schuster-rainer close this issue?

jxsl13 avatar Jul 14 '22 18:07 jxsl13