localfs

package
v0.166.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package localfs has suppliers using the local filesystem.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSystem

type FileSystem struct {
	// RootPath is an optional parameter to jail the file system access for file access.
	RootPath string
}

FileSystem provides local file system access through the filesystem.FileSystem interface.

Example
package main

import (
	"fmt"
	"github.com/adamluzsi/frameless/ports/filesystem"
	"io"
	"io/fs"
	"os"
	"path/filepath"

	"github.com/adamluzsi/frameless/adapters/localfs"
)

func main() {
	fsys := localfs.FileSystem{}

	file, err := fsys.OpenFile("test", os.O_RDWR|os.O_CREATE|os.O_EXCL, filesystem.ModeUserRWX)
	if err != nil {
		panic(err)
	}
	defer file.Close()

	file.Write([]byte("Hello world!"))
	file.Seek(0, io.SeekStart)

	bs, err := io.ReadAll(file)
	if err != nil {
		panic(err)
	}

	fmt.Println(string(bs)) // "Hello world!"

	file.Close()
	fsys.Remove("test")

	fsys.Mkdir("a", filesystem.ModeUserRWX)

	file2Name := filepath.Join("a", "test.txt")
	file2, err := filesystem.Create(fsys, file2Name)
	if err != nil {
		panic(err)
	}
	file2.Close()

	file2, err = filesystem.Open(fsys, file2Name)
	if err != nil {
		panic(err)
	}
	file2.Close()

	filesystem.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error {
		return fs.SkipDir
	})
}
Output:

func (FileSystem) Mkdir

func (fs FileSystem) Mkdir(name string, perm fs.FileMode) error

func (FileSystem) OpenFile

func (fs FileSystem) OpenFile(name string, flag int, perm fs.FileMode) (filesystem.File, error)

func (FileSystem) Remove

func (fs FileSystem) Remove(name string) error

func (FileSystem) Stat

func (fs FileSystem) Stat(name string) (fs.FileInfo, error)

Jump to

Keyboard shortcuts

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