osfs

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 6 Imported by: 2

Documentation

Overview

Package osfs provides a filesystem for the OS.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DirFS

func DirFS(dir string) fs.FS

DirFS returns a filesystem for the tree of files rooted at the directory dir. The filesystem can write using wfs.WriteFile(fsys fs.FS, name string, p []byte).

Example
package main

import (
	"fmt"
	"io/fs"
	"io/ioutil"
	"log"
	"os"

	"github.com/jarxorg/wfs"
	"github.com/jarxorg/wfs/osfs"
)

func main() {
	tmpDir, err := ioutil.TempDir("", "example")
	if err != nil {
		log.Fatal(err)
	}
	defer os.RemoveAll(tmpDir)

	name := "example.txt"
	content := []byte(`Hello`)

	fsys := osfs.DirFS(tmpDir)
	_, err = wfs.WriteFile(fsys, name, content, fs.ModePerm)
	if err != nil {
		log.Fatal(err)
	}

	wrote, err := ioutil.ReadFile(tmpDir + "/" + name)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%s\n", string(wrote))

}
Output:

Hello

Types

type OSFS

type OSFS struct {
	Dir string
	// contains filtered or unexported fields
}

OSFS represents a filesystem for the OS.

func New

func New(dir string) *OSFS

New returns a filesystem for the tree of files rooted at the directory dir.

func NewOSFS

func NewOSFS(dir string) *OSFS

NewOSFS returns a filesystem for the tree of files rooted at the directory dir. Deprecated: Use New.

func (*OSFS) CreateFile

func (fsys *OSFS) CreateFile(name string, mode fs.FileMode) (wfs.WriterFile, error)

CreateFile creates the named file.

func (*OSFS) Glob

func (fsys *OSFS) Glob(pattern string) ([]string, error)

Glob returns the names of all files matching pattern, providing an implementation of the top-level Glob function.

func (*OSFS) MkdirAll

func (fsys *OSFS) MkdirAll(dir string, mode fs.FileMode) error

MkdirAll creates the named directory.

func (*OSFS) Open

func (fsys *OSFS) Open(name string) (fs.File, error)

Open opens the named file.

func (*OSFS) ReadDir

func (fsys *OSFS) ReadDir(dir string) ([]fs.DirEntry, error)

ReadDir reads the named directory and returns a list of directory entries sorted by filename.

func (*OSFS) ReadFile

func (fsys *OSFS) ReadFile(name string) ([]byte, error)

ReadFile reads the named file and returns its contents.

func (*OSFS) RemoveAll

func (fsys *OSFS) RemoveAll(path string) error

RemoveAll removes path and any children it contains.

func (*OSFS) RemoveFile

func (fsys *OSFS) RemoveFile(name string) error

RemoveFile removes the specified named file.

func (*OSFS) Stat

func (fsys *OSFS) Stat(name string) (fs.FileInfo, error)

Stat returns a FileInfo describing the file. If there is an error, it should be of type *PathError.

func (*OSFS) Sub

func (fsys *OSFS) Sub(dir string) (fs.FS, error)

Sub returns an FS corresponding to the subtree rooted at dir.

func (*OSFS) WriteFile

func (fsys *OSFS) WriteFile(name string, p []byte, mode fs.FileMode) (int, error)

WriteFile writes the specified bytes to the named file.

Jump to

Keyboard shortcuts

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