Documentation ¶
Overview ¶
Package sample opens and encodes the example embedded text files. These files are used for demostrating the info and the view commands.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrEncode = errors.New("no encoding provided") ErrConvert = errors.New("unknown convert method") ErrConvNil = errors.New("conv argument cannot be empty") ErrName = errors.New("sample filename does not exist") ErrNotFound = errors.New("internal embed file is not found") )
var ANSI embed.FS
ANSI is the embedded file system with the ansi subdirectory.
var File embed.FS
File is the embedded file system with all the static files.
var PlainText embed.FS
PlainText is the embedded file system with the text subdirectory.
Functions ¶
func Map ¶
Map is the collection of sample text files. Each sample includes the output method, character encoding, the filename and a brief description.
Example ¶
package main import ( "fmt" "github.com/bengarrett/retrotxtgo/sample" ) func main() { s := sample.Map()["037"] fmt.Printf("%s - %s, %s", s.Name, s.Description, s.Encoding) }
Output: plaintext/cp037.txt - EBCDIC 037 IBM mainframe test, IBM Code Page 037
func Open ¶
Open the named sample text file. The byte array is encoded using the original character encoding.
Example ¶
package main import ( "fmt" "github.com/bengarrett/retrotxtgo/sample" ) func main() { b, _ := sample.Open("037") fmt.Print(len(b)) }
Output: 130
Types ¶
type Flags ¶
type Flags struct { Input encoding.Encoding // Input encoding is set using the input flag. Original bool // Original encoding is set using the original flag. }
Flags and configuration values by the user.
func (Flags) Open ¶
Open and convert the named sample text file into Unicode runes. Use the other open function to return the raw bytes in their original encoding.
Example ¶
package main import ( "fmt" "github.com/bengarrett/retrotxtgo/convert" "github.com/bengarrett/retrotxtgo/sample" "golang.org/x/text/encoding/charmap" ) func main() { c := convert.Convert{} f := sample.Flags{Input: charmap.CodePage037} r, _ := f.Open(&c, "037") fmt.Print(string(r[0:15])) }
Output: RetroTxt EBCDIC