Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement readString #607

Merged
merged 4 commits into from
Sep 22, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions io/bufio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ export class BufReader implements Reader {
* delim.
* For simple uses, a Scanner may be more convenient.
*/
async readString(_delim: string): Promise<string | Deno.EOF> {
throw new Error("Not implemented");
async readString(delim: string): Promise<string | Deno.EOF> {
const buffer = await this.readSlice(delim.charCodeAt(0));
dsseng marked this conversation as resolved.
Show resolved Hide resolved
return new TextDecoder().decode(buffer || undefined);
dsseng marked this conversation as resolved.
Show resolved Hide resolved
}

/** `readLine()` is a low-level line-reading primitive. Most callers should
Expand Down
9 changes: 9 additions & 0 deletions io/bufio_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ test(async function bufioBufferFull(): Promise<void> {
assertEquals(actual, "world!");
});

test(async function bufioReadString(): Promise<void> {
const string = "And now, hello, world!";
const buf = new BufReader(stringsReader(string), MIN_READ_BUFFER_SIZE);

const line = assertNotEOF(await buf.readString(","));
assertEquals(line, "And now,");
assertEquals(line.length, 8);
});

const testInput = encoder.encode(
"012\n345\n678\n9ab\ncde\nfgh\nijk\nlmn\nopq\nrst\nuvw\nxy"
);
Expand Down