filesystems

package
v0.94.1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	ModeUserR   = modeRead << modeUserShift
	ModeUserW   = modeWrite << modeUserShift
	ModeUserX   = modeExec << modeUserShift
	ModeUserRW  = ModeUserR | ModeUserW
	ModeUserRWX = ModeUserRW | ModeUserX

	ModeGroupR   = modeRead << modeGroupShift
	ModeGroupW   = modeWrite << modeGroupShift
	ModeGroupX   = modeExec << modeGroupShift
	ModeGroupRW  = ModeGroupR | ModeGroupW
	ModeGroupRWX = ModeGroupRW | ModeGroupX

	ModeOtherR   = modeRead << modeOtherShift
	ModeOtherW   = modeWrite << modeOtherShift
	ModeOtherX   = modeExec << modeOtherShift
	ModeOtherRW  = ModeOtherR | ModeOtherW
	ModeOtherRWX = ModeOtherRW | ModeOtherX

	ModeAllR   = ModeUserR | ModeGroupR | ModeOtherR
	ModeAllW   = ModeUserW | ModeGroupW | ModeOtherW
	ModeAllX   = ModeUserX | ModeGroupX | ModeOtherX
	ModeAllRW  = ModeAllR | ModeAllW
	ModeAllRWX = ModeAllRW | ModeGroupX
)

Variables

This section is empty.

Functions

func HasOpenFlagRead

func HasOpenFlagRead(flag int) bool

func HasOpenFlagWrite

func HasOpenFlagWrite(flag int) bool

Types

type DirEntry

type DirEntry = filesystem.DirEntry

type File

type File = filesystem.File

type FileInfo

type FileInfo = filesystem.FileInfo

type FileSystem

type FileSystem = filesystem.FileSystem

type Local

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

Local provides local file system access through the frameless.FileSystem interface.

Example
package main

import (
	"fmt"
	"io"
	"io/fs"
	"os"
	"path/filepath"

	"github.com/adamluzsi/frameless/ports/filesystem"

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

func main() {
	fsys := filesystems.Local{}

	file, err := fsys.OpenFile("test", os.O_RDWR|os.O_CREATE|os.O_EXCL, filesystems.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", filesystems.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 (Local) Mkdir

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

func (Local) OpenFile

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

func (Local) Remove

func (fs Local) Remove(name string) error

func (Local) Stat

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

type Memory

type Memory struct {
	// contains filtered or unexported fields
}
Example
package main

import (
	"fmt"
	"io"
	"io/fs"
	"os"
	"path/filepath"

	"github.com/adamluzsi/frameless/ports/filesystem"

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

func main() {
	fsys := &filesystems.Memory{}

	file, err := fsys.OpenFile("test", os.O_RDWR|os.O_CREATE|os.O_EXCL, filesystems.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", filesystems.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 (*Memory) Mkdir

func (mfs *Memory) Mkdir(name string, perm fs.FileMode) error

func (*Memory) OpenFile

func (mfs *Memory) OpenFile(name string, flag int, perm fs.FileMode) (File, error)

func (*Memory) Remove

func (mfs *Memory) Remove(name string) error

func (*Memory) Stat

func (mfs *Memory) Stat(name string) (fs.FileInfo, error)

type MemoryFile

type MemoryFile struct {
	// contains filtered or unexported fields
}

func (*MemoryFile) Close

func (f *MemoryFile) Close() error

func (*MemoryFile) Read

func (f *MemoryFile) Read(bytes []byte) (int, error)

func (*MemoryFile) ReadDir

func (f *MemoryFile) ReadDir(n int) ([]fs.DirEntry, error)

func (*MemoryFile) Seek

func (f *MemoryFile) Seek(offset int64, whence int) (int64, error)

func (*MemoryFile) Stat

func (f *MemoryFile) Stat() (fs.FileInfo, error)

func (*MemoryFile) Sync

func (f *MemoryFile) Sync() error

func (*MemoryFile) Write

func (f *MemoryFile) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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