diff options
| author | Vincent LE GOFF <g_n_s@hotmail.fr> | 2019-05-18 20:05:27 +0200 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2019-05-18 14:05:27 -0400 |
| commit | ef4fd3d4cac4bc7b6b105067b730dbb14b6d0bff (patch) | |
| tree | cb9dabd0551fddc7c655c47c0b57352f2f310eb7 /textproto/mod.ts | |
| parent | 715fe3300e33aa72ed7d4f8d39a021ca8ba54936 (diff) | |
Fix denoland/deno_std#409 handle multipart header in mime reader (denoland/deno_std#415)
Original: https://github.com/denoland/deno_std/commit/92c26cc33183284737fd41685b26a15cab07405d
Diffstat (limited to 'textproto/mod.ts')
| -rw-r--r-- | textproto/mod.ts | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/textproto/mod.ts b/textproto/mod.ts index 74c7b6662..72ecd252f 100644 --- a/textproto/mod.ts +++ b/textproto/mod.ts @@ -83,7 +83,8 @@ export class TextProtoReader { while (true) { let [kv, err] = await this.readLineSlice(); // readContinuedLineSlice - if (kv.byteLength == 0) { + + if (kv.byteLength === 0) { return [m, err]; } @@ -140,10 +141,15 @@ export class TextProtoReader { // Go's len(typed nil) works fine, but not in JS return [new Uint8Array(0), err]; } + // Avoid the copy if the first call produced a full line. if (line == null && !more) { + if (this.skipSpace(l) === 0) { + return [new Uint8Array(0), null]; + } return [l, null]; } + line = append(line, l); if (!more) { break; @@ -151,4 +157,15 @@ export class TextProtoReader { } return [line, null]; } + + skipSpace(l: Uint8Array): number { + let n = 0; + for (let i = 0; i < l.length; i++) { + if (l[i] === charCode(" ") || l[i] === charCode("\t")) { + continue; + } + n++; + } + return n; + } } |
