iconv-go: github.com/djimenez/iconv-go Index | Files | Directories

package iconv

import "github.com/djimenez/iconv-go"

Wraps the iconv API present on most systems, which allows for conversion of bytes from one encoding to another. This package additionally provides some convenient interface implementations like a Reader and Writer.

Index

Package Files

converter.go iconv.go reader.go writer.go

func Convert Uses

func Convert(input []byte, output []byte, fromEncoding string, toEncoding string) (bytesRead int, bytesWritten int, err error)

All in one Convert method, rather than requiring the construction of an iconv.Converter

func ConvertString Uses

func ConvertString(input string, fromEncoding string, toEncoding string) (output string, err error)

All in one ConvertString method, rather than requiring the construction of an iconv.Converter

type Converter Uses

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

func NewConverter Uses

func NewConverter(fromEncoding string, toEncoding string) (converter *Converter, err error)

Initialize a new Converter. If fromEncoding or toEncoding are not supported by iconv then an EINVAL error will be returned. An ENOMEM error maybe returned if there is not enough memory to initialize an iconv descriptor

func (*Converter) Close Uses

func (this *Converter) Close() (err error)

Close a Converter's iconv description explicitly

func (*Converter) Convert Uses

func (this *Converter) Convert(input []byte, output []byte) (bytesRead int, bytesWritten int, err error)

Convert bytes from an input byte slice into a give output byte slice

As many bytes that can converted and fit into the size of output will be processed and the number of bytes read for input as well as the number of bytes written to output will be returned. If not all converted bytes can fit into output and E2BIG error will also be returned. If input contains an invalid sequence of bytes for the Converter's fromEncoding an EILSEQ error will be returned

For shift based output encodings, any end shift byte sequences can be generated by passing a 0 length byte slice as input. Also passing a 0 length byte slice for output will simply reset the iconv descriptor shift state without writing any bytes.

func (*Converter) ConvertString Uses

func (this *Converter) ConvertString(input string) (output string, err error)

Convert an input string

EILSEQ error may be returned if input contains invalid bytes for the Converter's fromEncoding.

type Reader Uses

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

func NewReader Uses

func NewReader(source io.Reader, fromEncoding string, toEncoding string) (*Reader, error)

func NewReaderFromConverter Uses

func NewReaderFromConverter(source io.Reader, converter *Converter) (reader *Reader)

func (*Reader) Read Uses

func (this *Reader) Read(p []byte) (n int, err error)

implement the io.Reader interface

type Writer Uses

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

func NewWriter Uses

func NewWriter(destination io.Writer, fromEncoding string, toEncoding string) (*Writer, error)

func NewWriterFromConverter Uses

func NewWriterFromConverter(destination io.Writer, converter *Converter) (writer *Writer)

func (*Writer) Write Uses

func (this *Writer) Write(p []byte) (n int, err error)

implement the io.Writer interface

Directories

PathSynopsis
examples

Package iconv imports 4 packages (graph) and is imported by 77 packages. Updated 2016-07-20. Refresh now. Tools for package owners.