Giter Site home page Giter Site logo

gofat's Introduction

Actions Status CodeQL codecov

GoFAT

A FAT filesystem implementation in pure Go.
It implements the interface of afero.

Current Status

Readonly File access works great. Write support is missing, yet.

Usage

package main

import (
	"fmt"
	"io"
	"os"
	"github.com/aligator/gofat"
	"github.com/spf13/afero"
)

func main() {
	// Get any io.ReadSeeker implementation which provides a reader to a FAT32 filesystem.
	// You can use for example os.Open(...) to open an image file or even a `/dev/sdxy` device file from linux. 
	var reader io.ReadSeeker = ...

	// Then create a new GoFAT filesystem from the reader.
	fat, err := gofat.New(reader)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	// Now you can access any method from the afero.Fs filesystem like for example afero.Walk.
	_ := afero.Walk(fat, "/", func(path string, info os.FileInfo, err error) error {
		if err != nil {
			fmt.Println(err)
			return err
		}
		fmt.Println(path, info.IsDir())
		return nil
	})

	// You can also access some FAT specific fields.
	fmt.Printf("Opened volume '%v' with type %v\n\n", fat.Label(), fat.FSType())
}

That's it!

Compatibility with Go 1.16

As the Go 1.16 fs.FS interface is not fully compatible with the afero.Fs interface, it cannot be used with that directly. But I added a simple wrapper around it.
You can either just wrap an existing fat fs:

gofs := GoFs{*fs}

Or directly create a new one using NewGoFS(...) or NewGoFSSkipChecks(...).
Note that this wrapper has a small overhead, especially ReadDir because the result has to be converted to []fs.DirEntry.

I also added testing.fstest to the unit tests.

Test images

To get access to some test-images which already contain a FAT filesystem just run

go generate

This will extract the test images into ./testdata.

Contribution

Contributions are welcome, just create issues or even better PRs. You may open a draft or issue first to discuss the changes you would like to implement.

You may use github.com/cweill/gotests to generate your test boilerplate code.

Some resources on how FAT works are:

ToDo

  • more tests
  • implement some more attributes (e.g. hidden)
  • implement write support
  • support FAT12
  • check if compatibility with TinyGo for microcontrollers is possible. That would be a good use case for this lib...
  • use for a fuse filesystem driver

gofat's People

Contributors

aligator avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

izouxv

gofat's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.