Browse Source

rename Copy => CopyAll, update docs

master v1.0.0
AJ ONeal 4 years ago
parent
commit
27eee51fbe
  1. 38
      README.md
  2. 4
      copy.go
  3. 4
      copy_test.go

38
README.md

@ -1,21 +1,49 @@
# vfscopy
# [vfscopy](https://git.rootprojects.org/root/vfscopy)
Copy a Virtual FileSystem, such as
Recursively copy a Virtual FileSystem, such as
[http.FileSystem](https://golang.org/pkg/net/http/#FileSystem),
recursively to a native file system destination.
to a native file system destination.
Works with any file system that implements http.FileSystem,
such as `vfsgen`, `fileb0x`, `gobindata`.
including `vfsgen`, `fileb0x`, `gobindata` and most others.
## Example: native file system (os)
```go
httpfs := http.Dir("/tmp/public/")
vfs := vfscopy.NewVFS(httpfs)
if err := Copy(vfs, ".", "/tmp/dst/"); nil != err {
if err := vfscopy.CopyAll(vfs, ".", "/tmp/dst/"); nil != err {
fmt.Fprintf(os.Stderr, "couldn't copy vfs: %v\n", err)
}
```
## 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

4
copy.go

@ -13,8 +13,8 @@ const (
tmpPermissionForDirectory = os.FileMode(0755)
)
// Copy copies src to dest, doesn't matter if src is a directory or a file.
func Copy(vfs FileSystem, src, dest string, opt ...Options) error {
// CopyAll copies src to dest, doesn't matter if src is a directory or a file.
func CopyAll(vfs FileSystem, src, dest string, opt ...Options) error {
// FYI: os.Open does a proper lstat
f, err := vfs.Open(src)
if err != nil {

4
copy_test.go

@ -26,7 +26,7 @@ func TestNativeRecursiveCopy(t *testing.T) {
_ = os.RemoveAll(tmpDir)
}()
if err := Copy(vfs, ".", tmpDir, opts); nil != err {
if err := CopyAll(vfs, ".", tmpDir, opts); nil != err {
t.Errorf("error: %v", err)
return
}
@ -48,7 +48,7 @@ func TestVFSRecursiveCopy(t *testing.T) {
_ = os.RemoveAll(tmpDir)
}()
if err := Copy(vfs, ".", tmpDir, opts); nil != err {
if err := CopyAll(vfs, ".", tmpDir, opts); nil != err {
t.Errorf("copy error: %v", err)
return
}

Loading…
Cancel
Save