Coder Social home page Coder Social logo

go-qprintable's Introduction

Package qprintable implements quoted-printable encoding as specified by RFC 2045. It is strict on ouput, generous on input.

Quoting RFC 2045:

The Quoted-Printable encoding is intended to represent data that largely consists of octets that correspond to printable characters in the US-ASCII character set. It encodes the data in such a way that the resulting octets are unlikely to be modified by mail transport. If the data being encoded are mostly US-ASCII text, the encoded form of the data remains largely recognizable by humans. A body which is entirely US-ASCII may also be encoded in Quoted-Printable to ensure the integrity of the data should the message pass through a character-translating, and/or line-wrapping gateway.

VARIABLES

var BinaryEncoding = &Encoding{false, ""}

In binary encoding, CR and LF characters are treated like other control characters sequence and are escaped.

var MacTextEncoding = &Encoding{true, "\r"}

var UnixTextEncoding = &Encoding{true, "\n"}

var WindowsTextEncoding = &Encoding{true, "\r\n"}

A text encoding has to convert its input in the canonical form (as defined by RFC 2045) : native ends of line (CR for MacTextEncoding, LF for UnixTextEncoding, CRLF for WindowsTextEncoding) are converted into CRLF sequences. Non-native EOL sequences (for example, CR on UnixTextEncoding) are treated as control characters and escaped.

In the decoding process, CRLF sequences are converted to native ends of line.

FUNCTIONS

func NewDecoder(enc *Encoding, r io.Reader) io.Reader

Returns a new decoder. Data will be read from r, and decoded according to enc.

func NewEncoder(enc *Encoding, w io.Writer) io.WriteCloser

Returns a new encoder. Any data passed to Write will be encoded according to enc and then written to w.

Data passed to Write must be in its canonical form. The canonical form depends on the encoding:

  • for binary encoding, anything goes.
  • for text encodings, there shouldn't be any CR or LF characters other than the one used for end-of-line representation, that is, LF on Unix, CR on old Mac, CR+LF on Windows.

It is the responsibility of the caller to ensure that the input stream is in its canonical form. Any CR of LF character which is not part of an end-of-line representation will be quoted.

This returns a WriteCloser, but Close has no effect for encoding other than WindowsEncoding.

For WindowsEncoding, any trailing CR will not be written unless you call this function. However, note that for a text conforming to windows canonical form, this should never happen. So this function is useful only for invalid WindowsEncoding text streams, you can safely ignore it in all other cases.

TYPES

type Encoding struct {
	// contains unexported fields
}

func DetectEncoding(data string) *Encoding

Try to detect encoding of string:

  • strings with no \r will be Unix
  • strings with \r and no \n will be Mac
  • strings with count(\r\n) == count(\r) == count(\n) will be Windows
  • other strings will be binary

go-qprintable's People

Contributors

sloonz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.