`io.readLines` yield incomplete lines
See original GitHub issueDescribe the bug
It seems io.readLines
yield incomplete lines in some cases.
To Reproduce
Add gen.ts
as
import { parse } from "https://deno.land/std@0.105.0/flags/mod.ts";
const opts = parse(Deno.args)
const size = opts.size || 128;
const v = "x".repeat(1024 * size);
const b = new TextEncoder().encode(`["${v}"]`);
await Deno.stdout.write(b);
console.log("");
And add test.ts
as
import * as io from "https://deno.land/std@0.100.0/io/mod.ts";
for await (const line of io.readLines(Deno.stdin)) {
console.log(`Recv ${line.length}`);
if (!line) {
continue;
}
JSON.parse(line);
}
When the buffer size is small enough, it process successfully.
deno run gen.ts --size=1 | deno run test.ts
Check file:///Users/alisue/ghq/github.com/lambdalisue/deno-io-test/gen.ts
Check file:///Users/alisue/ghq/github.com/lambdalisue/deno-io-test/test.ts
Recv 1028
Recv 0
But when the buffer size is big, io.readLines
yield incomplete lines like
deno run gen.ts --size=100 | deno run test.ts
Check file:///Users/alisue/ghq/github.com/lambdalisue/deno-io-test/gen.ts
Check file:///Users/alisue/ghq/github.com/lambdalisue/deno-io-test/test.ts
Recv 16384
error: Uncaught (in promise) SyntaxError: Unexpected end of JSON input
JSON.parse(line);
^
at JSON.parse (<anonymous>)
at file:///Users/alisue/ghq/github.com/lambdalisue/deno-io-test/test.ts:8:8
Expected behavior
io.readLines
waits for a complete line.
Desktop (please complete the following information):
- OS: macOS 11.5
- Version
deno 1.13.0 (release, x86_64-apple-darwin)
v8 9.3.345.11
typescript 4.3.5
Additional context https://github.com/lambdalisue/deno-io-test
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
TextReader.ReadLine returns incomplete lines - Stack Overflow
I am using a Socket to receive data via TCP, and TextReader.ReadLine to read lines from the connection. There is a problem where...
Read more >readLines: Read Text Lines from a Connection - Rdrr.io
For a non-blocking text-mode connection the incomplete line is pushed back, silently. For all other connections the line will be accepted, with a...
Read more >I accidently used `.readlines()`, but why does it look different ...
Read one entire line from the file. A trailing newline character is kept in the string (but may be absent when a file...
Read more >Class: IO (Ruby 2.5.0)
Reads the entire file specified by name as individual lines, and returns those lines in an array. Lines are separated by sep. a...
Read more >C#: File.ReadLines() vs File.ReadAllLines() - Medium
ReadAllLines() reads the entire file at once and returns a string[] where each item of the array corresponds to a line of the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sorry, I was cofused. This is not a cause of deno. Please close this,
Oops. I’ve forgotten about why there is the
writeAll
function… As you said, I could not find any issue with the followinggen.ts
It can handle
1024 * 1024
data, so it seems it’s no longer an issue for me. Let wait for what @mattn can provide…