files

package
v0.24.5 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Overview

Package files: a grab bag of functions for reading and writing files.

grab bag of file utility functions

Index

Constants

View Source
const SaveFileExtension = ".tap"

Variables

This section is empty.

Functions

func Compact

func Compact(str string) (ret string)

take existing json data and minimize it. on error, logs and returns the empty string

func FindLatestNameWithTime

func FindLatestNameWithTime(dir, prefix, ext string) (ret string, err error)

returns the name.ext ( no path ) assumes files are formatted with NameWithTime

func FormattedLoad

func FormattedLoad(inPath string, pv *map[string]any) (err error)

write a .if or .tell tapestry file determines the type from the passed path.

func FormattedRead

func FormattedRead(in io.Reader, ext Extension, pv *map[string]any) (err error)

read a .if or .tell tapestry file

func FormattedSave

func FormattedSave(outPath string, data any, pretty bool) (err error)

write a .if or .tell tapestry file determines the type from the passed path.

func FormattedWrite

func FormattedWrite(w io.Writer, data any, ext Extension, pretty bool) (err error)

write a .if or .tell story file

func GetVersion

func GetVersion(details bool) (ret string)

for lack of a better place... here we arere.

func Indent

func Indent(str string) (ret string)

take existing json data and prettify it. on error, logs and returns the empty string

func IsValidExtension

func IsValidExtension(path string, exts []string) (okay bool)

is the extension of the passed path one of the specified extensions?

func LoadJson

func LoadJson(inPath string, out any) (err error)

deserialize from the passed path

func LoadTell

func LoadTell(inPath string) (ret any, err error)

deserialize from the passed path

func NameWithTime

func NameWithTime(prefix, ext string) (ret string)

golang doesn't provide file creation time in a cross-platform way so we add the current time to the name ( base 36 ) future: include a user specified tag ( separated by a hash or something. )

func ReadFile

func ReadFile(path string) ([]byte, error)

read the complete contents of the passed file

func ReadJson

func ReadJson(in io.Reader, out any) (err error)

func ReadPaths

func ReadPaths(filePaths string, recusive bool, exts []string, onFile func(string) error) (err error)

read a comma-separated list of files and directories for directories, ext ( a list of file extensions ) optionally filters the files. fix? maybe filepaths could be turned into an io.fs?

func ReadTell

func ReadTell(in io.Reader) (any, error)

func ReadTellRunes

func ReadTellRunes(in io.RuneReader, includeComments bool) (ret any, err error)

reads until the passed reader is exhausted ( hits eof ) returns nil error when finished. includeComments helps with testing

func SaveJson

func SaveJson(outPath string, data any, pretty bool) (err error)

serialize to the passed path

func SaveTell

func SaveTell(outPath string, data any) (err error)

serialize to the passed path

func WriteTell

func WriteTell(w io.Writer, data any) (err error)

serialize to the passed open file

Types

type Extension

type Extension int
const (
	BlockExt   Extension = iota + 1 // .block
	CompactExt                      // .if
	SpecExt                         // .ifspecs
	TellSpec                        // .tells
	TellStory                       // .tell
)

func Ext

func Ext(name string) (ret Extension)

given a file name, return its extension 0, Invalid if it isn't a known extension.

func SplitExt

func SplitExt(name string) (ret string, ext Extension)

given a file name, return its extension and the name without the extension. 0, Invalid if it isn't a known extension.

func (Extension) Blockly

func (ext Extension) Blockly() bool

blockly's format.

func (Extension) IsValid

func (ext Extension) IsValid() bool

func (Extension) Json

func (ext Extension) Json() bool

json message format ( excludes the deprecated detailed format )

func (Extension) Spec

func (ext Extension) Spec() bool

func (Extension) Story

func (ext Extension) Story() bool

func (Extension) String

func (i Extension) String() string

func (Extension) Tell

func (ext Extension) Tell() bool

uses the format described by github.com/ionous/tell.

type JsonFlags

type JsonFlags int
const (
	RawJson JsonFlags = 0
	Pretty  JsonFlags = 1 << iota
	EscapeHtml
)

func MakeJsonFlags

func MakeJsonFlags(pretty, escape bool) (ret JsonFlags)

type PlainDecoder

type PlainDecoder interface {
	Decode(into any) error
}

matches https://pkg.golang.ir/encoding/json#Decoder.Decode

type PlainEncoder

type PlainEncoder interface {
	Encode(from any) error
}

matches https://pkg.golang.ir/encoding/json#Encoder.Encode

func JsonEncoder

func JsonEncoder(w io.Writer, f JsonFlags) PlainEncoder

func TellEncoder

func TellEncoder(w io.Writer) PlainEncoder

Jump to

Keyboard shortcuts

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