memfs

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: 11 Imported by: 1

Documentation

Overview

Package memfs provides an in-memory filesystem.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemFS

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

MemFS represents an in-memory filesystem. MemFS keeps fs.FileMode but that permission is not checked.

func New

func New() *MemFS

New returns a new MemFS.

Example
package main

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

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

func main() {
	name := "path/to/example.txt"
	content := []byte(`Hello`)

	fsys := memfs.New()
	var err error
	_, err = wfs.WriteFile(fsys, name, content, fs.ModePerm)
	if err != nil {
		log.Fatal(err)
	}

	wrote, err := fs.ReadFile(fsys, name)
	if err != nil {
		log.Fatal(err)
	}

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

}
Output:

Hello

func (*MemFS) CreateFile

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

CreateFile creates the named file.

func (*MemFS) Glob

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

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

func (*MemFS) MkdirAll

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

MkdirAll creates the named directory.

func (*MemFS) Open

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

Open opens the named file.

func (*MemFS) ReadDir

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

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

func (*MemFS) ReadFile

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

ReadFile reads the named file and returns its contents.

func (*MemFS) RemoveAll

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

RemoveAll removes path and any children it contains.

func (*MemFS) RemoveFile

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

RemoveFile removes the specified named file.

func (*MemFS) Stat

func (fsys *MemFS) 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 (*MemFS) Sub

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

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

func (*MemFS) WriteFile

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

WriteFile writes the specified bytes to the named file.

type MemFile

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

MemFile represents an in-memory file. MemFile implements fs.File, fs.ReadDirFile and wfs.WriterFile.

func (*MemFile) Close

func (f *MemFile) Close() error

Close closes streams.

func (*MemFile) Read

func (f *MemFile) Read(p []byte) (int, error)

Read reads bytes from this file.

func (*MemFile) ReadDir

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

ReadDir reads sub directories.

func (*MemFile) Stat

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

Stat returns the fs.FileInfo of this file.

func (*MemFile) Write

func (f *MemFile) Write(p []byte) (int, error)

Write writes the specified bytes to this file.

Jump to

Keyboard shortcuts

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