fs

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyAllToDir

func CopyAllToDir(src fs.FS, dest string) error

CopyAllToDir copies all entries from src filesystem to destintation dir.

Example
package main

import (
	"log"
	"os"
	"path/filepath"

	"github.com/b4fun/battery/fs"
	"github.com/b4fun/battery/fs/testdata"
)

func main() {
	tempDir, err := os.MkdirTemp("", "battery-fs")
	if err != nil {
		log.Fatal(err)
	}
	defer os.RemoveAll(tempDir)

	err = fs.CopyAllToDir(testdata.Root, tempDir)
	if err != nil {
		log.Fatal(err)
	}

	walkErr := filepath.Walk(tempDir, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		log.Printf("%s %s", path, info.Mode())
		return nil
	})
	if walkErr != nil {
		log.Fatal(walkErr)
	}
}
Output:

Types

type WritableFS

type WritableFS interface {
	// OpenFile opens the named file with specified flag.
	// TODO: define the behavior
	OpenFile(name string, flag int, perm os.FileMode) (WriteableFile, error)

	// MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error.
	// TODO: define the behavior
	MkdirAll(path string, perm os.FileMode) error
}

WritableFS provides a writeable FS interface for interacting with the file system. See: https://github.com/golang/go/issues/45757

type WriteableFile

type WriteableFile interface {
	// Write writes len(b) bytes to the File.
	// It returns the number of bytes written and an error, if any.
	// Write returns a non-nil error when n != len(b).
	Write([]byte) (int, error)

	// Close closes the file.
	Close() error
}

WriteableFile provides the write interface for a file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL