Socket
Socket
Sign inDemoInstall

github.com/liamg/memoryfs

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/liamg/memoryfs


Version published
Created
Source

memoryfs

An in-memory filesystem implementation of io/fs.FS.

memoryfs implements all of the currently defined io/fs interfaces:

  • fs.FS
  • fs.GlobFS
  • fs.ReadDirFS
  • fs.ReadFileFS
  • fs.StatFS
  • fs.SubFS

It also allows the creation of files and directories.

Example

package main

import (
    "fmt"
    "io/fs"

    "github.com/liamg/memoryfs"
)

func main() {

    memfs := memoryfs.New()

    if err := memfs.MkdirAll("my/dir", 0o700); err != nil {
        panic(err)
    }

    if err := memfs.WriteFile("my/dir/file.txt", []byte("hello world"), 0o600); err != nil {
        panic(err)
    }

    data, err := fs.ReadFile(memfs, "my/dir/file.txt")
    if err != nil {
        panic(err)
    }

    fmt.Println(string(data))
}

Lazy Loading

If you are mirroring a disk file-system in memory, it can become very inefficient when large files are in use. For this scenario, the WriteLazyFile method is recommended. It allows you to add a file whose content will be provided on-demand by calling the LazyOpener function.

FAQs

Package last updated on 24 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc