vfscopy/README.md

64 lines
1.3 KiB
Markdown
Raw Permalink Normal View History

2020-10-23 21:38:54 +00:00
# [vfscopy](https://git.rootprojects.org/root/vfscopy)
2020-10-23 20:29:09 +00:00
2020-10-23 21:38:54 +00:00
Recursively copy a Virtual FileSystem, such as
2020-10-23 20:29:09 +00:00
[http.FileSystem](https://golang.org/pkg/net/http/#FileSystem),
2020-10-23 21:38:54 +00:00
to a native file system destination.
2020-10-23 20:29:09 +00:00
2020-10-23 21:30:03 +00:00
Works with any file system that implements http.FileSystem,
2020-10-23 21:38:54 +00:00
including `vfsgen`, `fileb0x`, `gobindata` and most others.
## Example: native file system (os)
2020-10-23 21:30:03 +00:00
2020-10-23 20:29:09 +00:00
```go
httpfs := http.Dir("/tmp/public/")
vfs := vfscopy.NewVFS(httpfs)
2020-10-23 21:38:54 +00:00
if err := vfscopy.CopyAll(vfs, ".", "/tmp/dst/"); nil != err {
2020-10-23 20:29:09 +00:00
fmt.Fprintf(os.Stderr, "couldn't copy vfs: %v\n", err)
}
```
2020-10-23 21:38:54 +00:00
## Example: vfsgen
**Note**: `vfsgen` does not support symlinks or file permissions.
```go
package main
import (
"fmt"
"git.rootprojects.org/root/vfscopy"
// vfsgen-generated file system
"git.example.com/org/project/assets"
)
func main() {
vfs := vfscopy.NewVFS(assets.Assets)
if err := vfscopy.CopyAll(vfs, ".", "/tmp/dst/"); nil != err {
fmt.Fprintf(os.Stderr, "couldn't copy vfs: %v\n", err)
}
fmt.Println("Done.")
}
```
## Test
```bash
2020-10-23 21:30:03 +00:00
# Generate the test virtual file system
go generate ./...
2020-10-23 21:30:03 +00:00
# Run the tests
go test ./...
```
2020-10-23 21:30:03 +00:00
# License
The MIT License (MIT)
We used the recursive native file system copy implementation at
https://github.com/otiai10/copy as a starting point and added
virtual file system support.