Skip to content

Commit

Permalink
Remove deprecated iterateReader
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Dec 14, 2023
1 parent 9a58aae commit 5606fd4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ It's heavily inspired from [ddskk](https://github.com/skk-dev/ddskk) and

# Documentation

See
[doc](https://github.com/vim-skk/skkeleton/tree/main/doc/skkeleton.jax)
See [doc](https://github.com/vim-skk/skkeleton/tree/main/doc/skkeleton.jax)

# Requirements

Expand Down
2 changes: 1 addition & 1 deletion denops/skkeleton/deps/std/streams.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { iterateReader } from "https://deno.land/[email protected]/streams/mod.ts";
export { TextLineStream } from "https://deno.land/[email protected]/streams/mod.ts";
31 changes: 26 additions & 5 deletions denops/skkeleton/jisyo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { wrap } from "./deps/iterator_helpers.ts";
import { JpNum } from "./deps/japanese_numeral.ts";
import { RomanNum } from "./deps/roman.ts";
import { zip } from "./deps/std/collections.ts";
import { iterateReader } from "./deps/std/streams.ts";
import { TextLineStream } from "./deps/std/streams.ts";
import { assert, is } from "./deps/unknownutil.ts";
import { Encode } from "./types.ts";
import { jisyoschema, jsonschema, msgpack, yaml } from "./deps/jisyo.ts";
Expand Down Expand Up @@ -524,6 +524,25 @@ function decode(str: Uint8Array, encode: Encoding): string {
return decoder.decode(str);
}

async function* iterLine(
r: ReadableStream<Uint8Array>,
encoding: string,
): AsyncIterable<string> {
const lines = r
.pipeThrough(new TextDecoderStream(encoding), {
preventAbort: true,
preventCancel: true,
preventClose: true,
})
.pipeThrough(new TextLineStream());

for await (const line of lines) {
if ((line as string).length) {
yield line as string;
}
}
}

export class SkkServer implements Dictionary {
#conn: Deno.Conn | undefined;
responseEncoding: Encoding;
Expand All @@ -545,8 +564,9 @@ export class SkkServer implements Dictionary {

await this.#conn.write(encode(`1${word} `, this.requestEncoding));
const result: string[] = [];
for await (const res of iterateReader(this.#conn)) {
const str = decode(res, this.responseEncoding);
for await (
const str of iterLine(this.#conn.readable, this.responseEncoding)
) {
result.push(...(str.at(0) === "4") ? [] : str.split("/").slice(1, -1));

if (str.endsWith("\n")) {
Expand Down Expand Up @@ -590,8 +610,9 @@ export class SkkServer implements Dictionary {

await this.#conn.write(encode(`4${prefix} `, this.requestEncoding));
const midashis: string[] = [];
for await (const res of iterateReader(this.#conn)) {
const str = decode(res, this.responseEncoding);
for await (
const str of iterLine(this.#conn.readable, this.responseEncoding)
) {
midashis.push(...(str.at(0) === "4") ? [] : str.split("/").slice(1, -1));

if (str.endsWith("\n")) {
Expand Down

0 comments on commit 5606fd4

Please sign in to comment.