Skip to content
Deno script to read a file line by line
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Main scripts are lines.ts and input.ts.

Cat Example

See the ./examples/cat.ts for an example to run. You can compare this with the cat implementation on deno's examples in the std library. This script's time spent seems to be roughly 3x slower than deno's cat example on my Macbook Pro's native terminal. Note that the time before the commands below work on bash.

This example:

$ time deno -A examples/cat.ts mobydick.txt

or if you didn't install it yet:

$ time deno -A mobydick.txt

Deno's cat example

$ time deno -A mobydick.txt

You can download the mobydick.txt from project gutenberg or curl it (Mac/Linux) from there like so:

$ curl -o mobydick.txt

Input Example

The lines function's async iterator can be used directly like in ./input.ts. The input reader created in that file is somewhat similar in style to pythons input function. An example using the input method is given in ./examples/input.ts

Try it out

$ deno

Here's an example run of the program

$ deno
Enter a number: 2
Enter another number: 3
2 + 3 = 5

Generating a long single line file

You can generate a large single line file by running the ./createTestFile.ts script like so: (requires file redirect shown is in unix)

deno createTestFile.ts > example.txt

The buffered lines cat example should be able to run with a long single file

deno examples/cat.ts example.txt

But the string lines cat example should run out of memory because the string being built for the line will get too large. I don't know a good way to get around this and keep the nice string api.

deno examples/cat2.ts example.txt
You can’t perform that action at this time.