Documentation
¶
Overview ¶
Example (HttpFileServer) ¶
ExampleHTTPFileServer demonstrates how to serve the contents of a tar file using HTTP
package main
import (
"io"
"net/http"
"net/http/httptest"
"os"
"github.com/nlepage/go-tarfs"
)
func main() {
tf, err := os.Open("test.tar")
if err != nil {
panic(err)
}
defer tf.Close()
tfs, err := tarfs.New(tf)
if err != nil {
panic(err)
}
srv := httptest.NewServer(http.FileServer(http.FS(tfs)))
defer srv.Close()
res, err := srv.Client().Get(srv.URL + "/dir1/dir11/file111")
if err != nil {
panic(err)
}
if _, err := io.Copy(os.Stdout, res.Body); err != nil {
panic(err)
}
res.Body.Close()
}
Output: file111
Example (Stat) ¶
Example_stat demonstrates how to read a file info from within a tar
package main
import (
"fmt"
"io/fs"
"os"
"github.com/nlepage/go-tarfs"
)
func main() {
tf, err := os.Open("test.tar")
if err != nil {
panic(err)
}
defer tf.Close()
tfs, err := tarfs.New(tf)
if err != nil {
panic(err)
}
fi, err := fs.Stat(tfs, "dir1/dir11/file111")
if err != nil {
panic(err)
}
fmt.Println(fi.Name())
fmt.Println(fi.IsDir())
fmt.Println(fi.Size())
}
Output: file111 false 7
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNotDir = errors.New("not a directory") ErrDir = errors.New("is a directory") )
Generic errors
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.