diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2020-04-28 17:40:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-28 12:40:43 -0400 |
commit | 678313b17677e012ba9a07aeca58af1aafbf4e8c (patch) | |
tree | e48e25b165a7d6d566095442448f2e36fa09c561 /std/textproto | |
parent | 47c2f034e95696a47770d60aec1362501e7f330d (diff) |
BREAKING: Remove Deno.EOF, use null instead (#4953)
Diffstat (limited to 'std/textproto')
-rw-r--r-- | std/textproto/mod.ts | 18 | ||||
-rw-r--r-- | std/textproto/test.ts | 29 |
2 files changed, 24 insertions, 23 deletions
diff --git a/std/textproto/mod.ts b/std/textproto/mod.ts index 218ec9d44..ca14c0546 100644 --- a/std/textproto/mod.ts +++ b/std/textproto/mod.ts @@ -22,9 +22,9 @@ export class TextProtoReader { /** readLine() reads a single line from the TextProtoReader, * eliding the final \n or \r\n from the returned string. */ - async readLine(): Promise<string | Deno.EOF> { + async readLine(): Promise<string | null> { const s = await this.readLineSlice(); - if (s === Deno.EOF) return Deno.EOF; + if (s === null) return null; return str(s); } @@ -48,20 +48,20 @@ export class TextProtoReader { * "Long-Key": {"Even Longer Value"}, * } */ - async readMIMEHeader(): Promise<Headers | Deno.EOF> { + async readMIMEHeader(): Promise<Headers | null> { const m = new Headers(); let line: Uint8Array | undefined; // The first line cannot start with a leading space. let buf = await this.r.peek(1); - if (buf === Deno.EOF) { - return Deno.EOF; + if (buf === null) { + return null; } else if (buf[0] == charCode(" ") || buf[0] == charCode("\t")) { line = (await this.readLineSlice()) as Uint8Array; } buf = await this.r.peek(1); - if (buf === Deno.EOF) { + if (buf === null) { throw new Deno.errors.UnexpectedEof(); } else if (buf[0] == charCode(" ") || buf[0] == charCode("\t")) { throw new Deno.errors.InvalidData( @@ -71,7 +71,7 @@ export class TextProtoReader { while (true) { const kv = await this.readLineSlice(); // readContinuedLineSlice - if (kv === Deno.EOF) throw new Deno.errors.UnexpectedEof(); + if (kv === null) throw new Deno.errors.UnexpectedEof(); if (kv.byteLength === 0) return m; // Key ends at first colon @@ -112,12 +112,12 @@ export class TextProtoReader { } } - async readLineSlice(): Promise<Uint8Array | Deno.EOF> { + async readLineSlice(): Promise<Uint8Array | null> { // this.closeDot(); let line: Uint8Array | undefined; while (true) { const r = await this.r.readLine(); - if (r === Deno.EOF) return Deno.EOF; + if (r === null) return null; const { line: l, more } = r; // Avoid the copy if the first call produced a full line. diff --git a/std/textproto/test.ts b/std/textproto/test.ts index b9947ab33..3b71bc08c 100644 --- a/std/textproto/test.ts +++ b/std/textproto/test.ts @@ -6,12 +6,7 @@ import { BufReader } from "../io/bufio.ts"; import { TextProtoReader } from "./mod.ts"; import { stringsReader } from "../io/util.ts"; -import { - assert, - assertEquals, - assertThrows, - assertNotEOF, -} from "../testing/asserts.ts"; +import { assert, assertEquals, assertThrows } from "../testing/asserts.ts"; const { test } = Deno; function reader(s: string): TextProtoReader { @@ -31,7 +26,7 @@ test({ test("[textproto] ReadEmpty", async () => { const r = reader(""); const m = await r.readMIMEHeader(); - assertEquals(m, Deno.EOF); + assertEquals(m, null); }); test("[textproto] Reader", async () => { @@ -43,7 +38,7 @@ test("[textproto] Reader", async () => { assertEquals(s, "line2"); s = await r.readLine(); - assert(s === Deno.EOF); + assert(s === null); }); test({ @@ -53,7 +48,8 @@ test({ "my-key: Value 1 \r\nLong-key: Even Longer Value\r\nmy-Key: " + "Value 2\r\n\n"; const r = reader(input); - const m = assertNotEOF(await r.readMIMEHeader()); + const m = await r.readMIMEHeader(); + assert(m !== null); assertEquals(m.get("My-Key"), "Value 1, Value 2"); assertEquals(m.get("Long-key"), "Even Longer Value"); }, @@ -64,7 +60,8 @@ test({ async fn(): Promise<void> { const input = "Foo: bar\n\n"; const r = reader(input); - const m = assertNotEOF(await r.readMIMEHeader()); + const m = await r.readMIMEHeader(); + assert(m !== null); assertEquals(m.get("Foo"), "bar"); }, }); @@ -74,7 +71,8 @@ test({ async fn(): Promise<void> { const input = ": bar\ntest-1: 1\n\n"; const r = reader(input); - const m = assertNotEOF(await r.readMIMEHeader()); + const m = await r.readMIMEHeader(); + assert(m !== null); assertEquals(m.get("Test-1"), "1"); }, }); @@ -89,7 +87,8 @@ test({ } const sdata = data.join(""); const r = reader(`Cookie: ${sdata}\r\n\r\n`); - const m = assertNotEOF(await r.readMIMEHeader()); + const m = await r.readMIMEHeader(); + assert(m !== null); assertEquals(m.get("Cookie"), sdata); }, }); @@ -106,7 +105,8 @@ test({ "Audio Mode : None\r\n" + "Privilege : 127\r\n\r\n"; const r = reader(input); - const m = assertNotEOF(await r.readMIMEHeader()); + const m = await r.readMIMEHeader(); + assert(m !== null); assertEquals(m.get("Foo"), "bar"); assertEquals(m.get("Content-Language"), "en"); // Make sure we drop headers with trailing whitespace @@ -174,7 +174,8 @@ test({ "------WebKitFormBoundaryimeZ2Le9LjohiUiG--\r\n\n", ]; const r = reader(input.join("")); - const m = assertNotEOF(await r.readMIMEHeader()); + const m = await r.readMIMEHeader(); + assert(m !== null); assertEquals(m.get("Accept"), "*/*"); assertEquals(m.get("Content-Disposition"), 'form-data; name="test"'); }, |