package quotedprintable

import "mime/quotedprintable"

Package quotedprintable implements quoted-printable encoding as specified by RFC 2045.

Index

Examples

Types

type Reader

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

Reader 是 quoted-printable 解码器。

func NewReader

func NewReader(r io.Reader) *Reader

NewReader 返回一个 quoted-printable 读取器,从 r 解码。

Example
package main

import (
	"fmt"
	"io"
	"mime/quotedprintable"
	"strings"
)

func main() {
	for _, s := range []string{
		`=48=65=6C=6C=6F=2C=20=47=6F=70=68=65=72=73=21`,
		`invalid escape: <b style="font-size: 200%">hello</b>`,
		"Hello, Gophers! This symbol will be unescaped: =3D and this will be written in =\r\none line.",
	} {
		b, err := io.ReadAll(quotedprintable.NewReader(strings.NewReader(s)))
		fmt.Printf("%s %v\n", b, err)
	}
}

Output:

Hello, Gophers! <nil>
invalid escape: <b style="font-size: 200%">hello</b> <nil>
Hello, Gophers! This symbol will be unescaped: = and this will be written in one line. <nil>

func (*Reader) Read

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

Read 从底层读取器读取并解码 quoted-printable 数据。

type Writer

type Writer struct {
	// Binary 模式将写入器的输入视为纯二进制,并将行尾字节作为二进制数据处理。
	Binary bool
	// contains filtered or unexported fields
}

A Writer is a quoted-printable writer that implements io.WriteCloser.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter 返回一个新的 Writer,写入到 w。

Example
package main

import (
	"mime/quotedprintable"
	"os"
)

func main() {
	w := quotedprintable.NewWriter(os.Stdout)
	w.Write([]byte("These symbols will be escaped: = \t"))
	w.Close()

}

Output:

These symbols will be escaped: =3D =09

func (*Writer) Close

func (w *Writer) Close() error

Close 关闭 Writer,将任何未写入的数据刷新到底层 io.Writer, 但不关闭底层的 io.Writer。

func (*Writer) Write

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

Write 使用 quoted-printable 编码将 p 写入底层 io.Writer。 它将行长度限制为 76 个字符。编码字节不会自动刷新直到 Writer 关闭。