RFC2045 第 6.8 节规定 Base64 输出的最大编码行长度应为 76 个字符或更少。
Golang 流编写器base64.NewEncoder没有任何行分割选项,如此处所示。
package main
import (
"encoding/base64"
"io"
"os"
"strings"
)
// See https://www.ietf.org/rfc/rfc2045.txt, section 6.8 for notes on maximum line length of 76 characters
func main() {
data := "It is only the hairs on a gooseberry that prevent it from being a grape! This is long enough to need a line split"
rdr := strings.NewReader(data)
wrt := base64.NewEncoder(base64.StdEncoding, os.Stdout)
io.Copy(wrt, rdr)
}
输出是
SXQgaXMgb25seSB0aGUgaGFpcnMgb24gYSBnb29zZWJlcnJ5IHRoYXQgcHJldmVudCBpdCBmcm9tIGJlaW5nIGEgZ3JhcGUhIEl0IGlzIG9ubHkgdGhlIGhhaXJzIG9uIGEgZ29vc2ViZXJyeSB0aGF0IHByZXZlbnQgaXQgZnJvbSBiZWluZyBhIGdyYXBl
是否有基于流的分割线解决方案?MIME库仅提供基于字符串的编码选项。
梦里花落0921
相关分类