Skip to content

Commit 4fb5e98

Browse files
authored
docs:update (#19)
1 parent 33e8d9e commit 4fb5e98

4 files changed

Lines changed: 13 additions & 12 deletions

File tree

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ MHTML Stream
55
[![npm](https://img.shields.io/npm/v/mhtml-stream)](https://www.npmjs.com/package/mhtml-stream)
66
[![license](https://img.shields.io/github/license/erikbrinkman/mhtml-stream)](LICENSE)
77

8-
Zero-dependency library for parsing MHTML data as streams using modern WHATWG
9-
streams and async iterators. Because it relies on modern cross javascript
10-
standards it works out-of-the-box in all javascript environments, with only a
11-
little tweaking necessary for module definitions.
8+
Library for parsing MHTML data as streams using modern WHATWG streams and async
9+
iterators. Because it relies on modern cross javascript standards it works
10+
out-of-the-box in all javascript environments, with only a little tweaking
11+
necessary for module definitions.
1212

1313
Usage
1414
-----
@@ -39,3 +39,7 @@ Notes
3939
comes to whether whitespace should be added when unfolding. This currently
4040
uses the first whitespace character to indicate folding, and preservers any
4141
others.
42+
- Decoded part content preserves the original MIME line endings. The parser
43+
splits the stream on `\r\n`, and the quoted-printable and 7bit/8bit decoders
44+
re-insert that `\r\n` between lines, so extraction is lossless. Both decoders
45+
accept a `newLine` argument if you'd rather normalize to `\n`.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mhtml-stream",
33
"version": "2.0.2",
4-
"description": "Zero dependency stream MHTML parser",
4+
"description": "Streaming MHTML parser",
55
"keywords": [
66
"mhtml",
77
"stream"

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ export async function* parseMhtml(
240240
const headers = await parseHeaders(lines);
241241
const [boundary, terminus] = bound ?? (bound = getBoundary(headers));
242242

243-
// Content-Transfer-Encoding token values are case-insensitive (RFC 2045)
244243
const encoding = (
245244
headers.get("Content-Transfer-Encoding") ?? "7bit"
246245
).toLowerCase();

src/utils.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ export async function collect(
127127
return concat(chunks);
128128
}
129129

130-
// CRLF, the canonical MIME line separator the stream is split on
131130
const crlf = new Uint8Array([13, 10]);
132131

133132
/** whether a character code is a hex digit (0-9, A-F, a-f) */
@@ -145,9 +144,8 @@ export function isHexDigit(code: number): boolean {
145144
* If quoted printable "lines" aren't escaped with an "=" then a new line needs
146145
* to be inserted. We use `newLine`, which defaults to CRLF to match the
147146
* canonical MIME form; pass a custom separator (e.g. a single "\n") to
148-
* normalize instead. The separator is emitted between lines, never after the
149-
* last one, since the CRLF preceding the MIME boundary belongs to the
150-
* delimiter, not the body.
147+
* normalize instead. The separator goes between lines; the CRLF before the MIME
148+
* boundary belongs to the delimiter, not the body.
151149
*/
152150
export async function* decodeQuotedPrintable(
153151
lines: AsyncIterable<Uint8Array>,
@@ -234,8 +232,8 @@ export async function* decodeBase64(
234232
* payload as-is. parseMhtml splits the stream on CRLF to find part boundaries,
235233
* so we re-insert `newLine` (defaulting to CRLF) between lines to restore the
236234
* original bytes exactly. Pass `newLine` (e.g. a single "\n") to normalize line
237-
* endings instead. The separator is emitted between lines, never after the last
238-
* one, since the CRLF preceding the boundary belongs to the delimiter.
235+
* endings instead. The separator goes between lines; the CRLF before the
236+
* boundary belongs to the delimiter, not the body.
239237
*/
240238
export async function* decodeIdentity(
241239
lines: AsyncIterable<Uint8Array>,

0 commit comments

Comments
 (0)