ioencoder

package module
v0.0.0-...-112aaa3 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2019 License: MIT Imports: 10 Imported by: 1

README

Wrapper for text/encoding

Allow to select correct encoder based on an encoder name

For latter use on Reading or Writing files, convert strings or byte array

Basic examples:

import (
    "github.com/hanspr/ioencoder"
)

func main() {
    // Create object
    enc := ioencoder.New()

    // Get a io.Reader and wrap with encoder
    file, err := os.Open(filename)
    utf8reader, err = enc.GetReader("iso-8859-1", file)
    // Code to read e Latin1 file and decode to UTF8

    // Encode - Decode a string
    txtbig5 := enc.EncodeString("BIG5", "這裡,可算是我的隨意空間吧")
    txtutf8 := enc.DecodeString("BIG5", txtbig5)

    // Get io.Wrtier and wrap with encoder
    if wfile, err = os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644); err == nil {
        writerutf8, err = enc.GetWriter("SHIFT-JIS", wfile)
        // Code to write to file encoded in SHIFT-JIS
    }
}
import (
    "github.com/hanspr/ioencoder"
)

func main() {
    // Creat object
    enc := ioencoder.New()
    enc.SetEncoding("ISO88592")

    // Use the selected encoder properties directly
    txtlatin1 := enc.encoder.String("latin1 string: áéíóúÑ")
    txtutf8 := enc.decoder.String(txtlatin1)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IoEncoder

type IoEncoder struct {
	// contains filtered or unexported fields
}

func New

func New() *IoEncoder

func (*IoEncoder) DecodeBytes

func (e *IoEncoder) DecodeBytes(encodername string, b []byte) []byte

func (*IoEncoder) DecodeString

func (e *IoEncoder) DecodeString(encodername, text string) string

func (*IoEncoder) EncodeBytes

func (e *IoEncoder) EncodeBytes(encodername string, b []byte) []byte

func (*IoEncoder) EncodeString

func (e *IoEncoder) EncodeString(encodername, text string) string

func (*IoEncoder) GetAvailableEncodings

func (e *IoEncoder) GetAvailableEncodings() []string

func (*IoEncoder) GetAvailableEncodingsAsString

func (e *IoEncoder) GetAvailableEncodingsAsString(separator string) string

func (*IoEncoder) GetReader

func (e *IoEncoder) GetReader(encodername string, r io.Reader) (io.Reader, error)

func (*IoEncoder) GetWriter

func (e *IoEncoder) GetWriter(encodername string, w io.Writer) (io.Writer, error)

func (*IoEncoder) SetEncoding

func (e *IoEncoder) SetEncoding(encodername string) error

Jump to

Keyboard shortcuts

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