Read a tar file contents using go1.16 io/fs abstraction
Install:
go get github.com/nlepage/go-tarfs
Use:
package main
import (
"os"
tarfs "github.com/nlepage/go-tarfs"
)
func main() {
tf, err := os.Open("path/to/archive.tar")
if err != nil {
panic(err)
}
defer tf.Close()
tfs, err := tarfs.New(tf)
if err != nil {
panic(err)
}
f, err := tfs.Open("path/to/some/file")
if err != nil {
panic(err)
}
defer f.Close() // frees the associated reader
// use f...
}
More information at pkg.go.dev/github.com/nlepage/go-tarfs
The io.Reader
given to tarfs.New
must stay opened while using the returned fs.FS
(this is true only if the io.Reader
implements io.ReaderAt
).
Since v1.2.0 files content are not stored in memory anymore if the io.Reader
given to tarfs.New
implements io.ReaderAt
.
For now, no effort is done to support symbolic links.
Give a ⭐️ if this project helped you!
Thanks goes to these wonderful people (emoji key):
Nicolas Lepage 💻 |
Jonas Plum |
MengYX 🐛 💻 |
Andrey Dyatlov 🐛 💻 |
Joe Lanford 💻 👀 🐛 |
This project follows the all-contributors specification. Contributions of any kind welcome!
This project is unlicensed, it is free and unencumbered software released into the public domain.