transfer

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package transfer contains utilities related to encoding and decoding transfer encodings, which interpret the Content-transfer-encoding header to apply certain 8bit to 7bit encodings. If a Content-transfer-encoding is present, only the values of quoted-printable and base64 will actually result in changes to the document being encoded or decoded. Other settings such as binary, 7bit, or 8bit will result in the bytes being left as-is.

For the sake of this module, the term "decoded" means that the content has been transformed from the named Content-transfer-encoding to the charset encoded form. Meanwhile, "encoded" means that the content has been transformed from the charset encoding to the named Content-transfer-encoding.

Index

Constants

View Source
const (
	None            = ""                 // bytes will be left as-is
	Bit7            = "7bit"             // bytes will be left as-is
	Bit8            = "8bit"             // bytes will be left as-is
	Binary          = "binary"           // bytes will be left as-is
	QuotedPrintable = "quoted-printable" // bytes will be transformed between quoted-printable and binary data
	Base64          = "base64"           // bytes will be transformed between base64 and binary data
)

Variables

AsIsTranscoder is just a shortcut to a no-op encoder/decoder.

Transcodings defines the supported Content-transfer-encodings and how to handle them. It can be modified to change the global handling of transfer encodings.

Functions

func ApplyTransferDecoding

func ApplyTransferDecoding(h *header.Header, r io.Reader) io.Reader

ApplyTransferDecoding returns an io.Reader that will modify incoming bytes according to the transfer encoding detected from the given header. (Or the io.Reader will leave the bytes as is if there's no transfer encoding or the transfer encoding is one that is interpreted as-is).

func ApplyTransferEncoding

func ApplyTransferEncoding(h *header.Header, w io.Writer) io.WriteCloser

ApplyTransferEncoding is a helper that will check the given header to see if transfer encoding ought to be performed. It will return an io.WritCloser that will write the encoding (or just pass data through if no encoding is necessary).

You must call Close() on the returned io.WriteCloser when you are finished writing.

func NewAsIsDecoder

func NewAsIsDecoder(r io.Reader) io.Reader

NewAsIsDecoder returns an io.Reader that reads bytes as-is.

func NewAsIsEncoder

func NewAsIsEncoder(w io.Writer) io.WriteCloser

NewAsIsEncoder returns an io.WriteCloser that writes bytes as-is.

func NewBase64Decoder

func NewBase64Decoder(r io.Reader) io.Reader

NewBase64Decoder will translate all bytes read from the given io.Reader as base64 and return the binary data to the returned io.Reader.

func NewBase64Encoder

func NewBase64Encoder(w io.Writer) io.WriteCloser

NewBase64Encoder will translate all bytes written to the returned io.WriteCloser into base64 encoding and write those to the give io.Writer.

func NewQuotedPrintableDecoder

func NewQuotedPrintableDecoder(r io.Reader) io.Reader

NewQuotedPrintableDecoder will read bytes from the given io.Reader and return them in the returned io.Reader after decoding them from quoted-printable format.

func NewQuotedPrintableEncoder

func NewQuotedPrintableEncoder(w io.Writer) io.WriteCloser

NewQuotedPrintableEncoder will transform all bytes written to the returned io.WriteCloser into quoted-printable form and write them to the given io.Writer.

Types

type Transcoding

type Transcoding struct {
	// Encoder returns an io.WriteCloser, which will encode binary data and
	// write the encoded form to the given io.Writer. You must call Close() on
	// the returned io.WriteCloser when you are finished.
	Encoder func(io.Writer) io.WriteCloser

	// Decoder returns an io.Reader, which will read from the given io.Reader
	// when read and decode the encoded data back into binary form the encoded
	// form.
	Decoder func(io.Reader) io.Reader
}

Transcoding is a pair of functions that can be used to transform to and from a transfer encoding.

Jump to

Keyboard shortcuts

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