fsx

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package fsx implements utility methods for dealing with Go's `io/fs` library.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileInfo

type FileInfo struct {
	Spec FileInfoSpec
}

FileInfo implements a basic version of `fs.FileInfo`

func NewFileInfo

func NewFileInfo(name string, size int) *FileInfo

NewFileInfo creates a new `FileInfo` from a name and size

Example
package main

import (
	"archive/tar"
	"bytes"
	"fmt"
	"io"
	"strings"

	"github.com/b1naryth1ef/sheath/fsx"
)

func main() {
	var buffer bytes.Buffer

	exampleFileData := "hello :3"
	exampleFileInfo := fsx.NewFileInfo("test.txt", len(exampleFileData))

	tw := tar.NewWriter(&buffer)
	header, _ := tar.FileInfoHeader(exampleFileInfo, "")
	tw.WriteHeader(header)
	io.Copy(tw, strings.NewReader(exampleFileData))

	fmt.Printf("Tar Size: %d\n", buffer.Len())
}
Output:

Tar Size: 520

func (*FileInfo) IsDir

func (f *FileInfo) IsDir() bool

func (*FileInfo) ModTime

func (f *FileInfo) ModTime() time.Time

func (*FileInfo) Mode

func (f *FileInfo) Mode() fs.FileMode

func (*FileInfo) Name

func (f *FileInfo) Name() string

func (*FileInfo) Size

func (f *FileInfo) Size() int64

func (*FileInfo) Sys

func (f *FileInfo) Sys() any

type FileInfoSpec

type FileInfoSpec struct {
	Name    string
	Size    int64
	Mode    fs.FileMode
	IsDir   bool
	Sys     any
	ModTime time.Time
}

FileInfoSpec contains the metadata required to implement `fs.FileInfo`

Jump to

Keyboard shortcuts

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