@portable/quoted-printable
Functions
QuotedPrintable.decode
Decodes quoted-printable (RFC 2045 section 6.7) into bytes. A string is read as UTF-8.
Whitespace at the end of a line and soft line breaks (= followed by CRLF, LF or the end of the
input) are removed, and =XX escapes with upper- or lowercase hex digits are decoded. Anything
else, including a malformed escape, is copied as is. Decoding never throws.
function decode(input: string | Uint8Array): Uint8Array<ArrayBuffer>;import * as QuotedPrintable from '@portable/quoted-printable';
new TextDecoder().decode(QuotedPrintable.decode('tere j=C3=B5geva')); // 'tere jõgeva'QuotedPrintable.encode
Encodes bytes as quoted-printable (RFC 2045 section 6.7). A string is encoded as UTF-8 first.
Line breaks in the input are kept, whitespace before a line break or at the end is escaped, and a hyphen that would start a line is escaped so that no line can be read as a MIME boundary.
function encode(
input: Uint8Array | string,
options: encode.Options = {},
): string;| Option | Type | Default | Description |
|---|---|---|---|
binary | boolean | false | Encode a CR or LF that is not part of a CRLF pair, so that a transport that rewrites line endings can't change the data. Use it for binary content. |
lineLength | number | false | 76 | Longest output line, not counting the line break. Longer lines are broken with soft line breaks (= followed by CRLF). An integer of at least 4, or false for no soft line breaks. Anything else throws a RangeError. |
import * as QuotedPrintable from '@portable/quoted-printable';
QuotedPrintable.encode('tere jõgeva'); // 'tere j=C3=B5geva'
QuotedPrintable.encode('a'.repeat(80)); // 75 a's, a soft line break ('=\r\n'), then 5 a'sClasses
QuotedPrintable.DecoderStream
A TransformStream that decodes quoted-printable text or bytes. Its output is the same as
decode() of the whole input, however the input is split into chunks.
class DecoderStream extends TransformStream<
string | Uint8Array,
Uint8Array<ArrayBuffer>
> {
constructor(options: DecoderStream.Options = {});
}| Option | Type | Default | Description |
|---|---|---|---|
signal | AbortSignal | Errors the stream with signal.reason when aborted, which cancels the source it is piped from. |
import * as QuotedPrintable from '@portable/quoted-printable';
const text = body
.pipeThrough(new QuotedPrintable.DecoderStream())
.pipeThrough(new TextDecoderStream());QuotedPrintable.EncoderStream
A TransformStream that encodes bytes or text as quoted-printable, emitted as ASCII bytes. Its
output is the same as encode() of the whole input, however the input is split into chunks.
class EncoderStream extends TransformStream<
Uint8Array | string,
Uint8Array<ArrayBuffer>
> {
constructor(options: EncoderStream.Options = {});
}| Option | Type | Default | Description |
|---|---|---|---|
binary | boolean | false | Encode a CR or LF that is not part of a CRLF pair, so that a transport that rewrites line endings can't change the data. Use it for binary content. |
lineLength | number | false | 76 | Longest output line, not counting the line break. Longer lines are broken with soft line breaks (= followed by CRLF). An integer of at least 4, or false for no soft line breaks. Anything else throws a RangeError. |
signal | AbortSignal | Errors the stream with signal.reason when aborted, which cancels the source it is piped from. |
import * as QuotedPrintable from '@portable/quoted-printable';
const body = file
.stream()
.pipeThrough(new QuotedPrintable.EncoderStream());