Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Seek() in archive file #323

Closed
nicola-spb opened this issue Feb 19, 2022 · 5 comments
Closed

Seek() in archive file #323

nicola-spb opened this issue Feb 19, 2022 · 5 comments

Comments

@nicola-spb
Copy link

nicola-spb commented Feb 19, 2022

Hello,

When i walking in archive I have fs.File (without Seek()). How can I get ReadSeeker interface of it?

fsys, err := archiver.FileSystem(sourcePath)
if err != nil {
	return nil, err
}
	
err = fs.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error {
	if err != nil {
		return err
	}

	f, err := fsys.Open(path)
	if err != nil {
		return err
	}
	defer f.Close()
	
	frs := f.(io.ReadSeeker)  // Error
}

Thanks

@mholt
Copy link
Owner

mholt commented Feb 19, 2022

I don't think the underlying archive format implementations (tar, zip, etc) give us Seek(), sorry.

It does seem like that should be able to work when dealing with regular files on disk, but this might be a feature request more for the standard library (or whatever package implements the underlying archive format).

Will close this, but feel free to continue discussion. I could very well be wrong.

@oliverpool
Copy link

I tried to implement a caddy module after the merge of caddyserver/caddy#4909 but it panics because of this:

http.stdlib	http: panic serving 127.0.0.1:46708: interface conversion: archiver.extractedFile is not io.ReadSeeker: missing method Seek

@oliverpool
Copy link

https://github.com/nlepage/go-tarfs works fine ! (since nlepage/go-tarfs#4)

@oliverpool
Copy link

I just realized, that it reads the whole file in memory: https://github.com/nlepage/go-tarfs/blob/bec76bb13b0a3be9e1bf8bb03141a6d26ce91902/fs.go#L39-L44 ...

@mholt
Copy link
Owner

mholt commented Aug 9, 2022

@oliverpool

I tried to implement a caddy module after the merge of caddyserver/caddy#4909 but it panics because of this:

Gah, I forgot about that.

I just realized, that it reads the whole file in memory: nlepage/go-tarfs@bec76bb/fs.go#L39-L44 ...

Yikes, haha. That probably won't do for production use. Thanks for experimenting with it!!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants