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.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
.editorconfig
.gitignore
LICENSE
createTestFile.ts
dev_deps.ts
input.ts
input_test.ts
lines.ts
lines_test.ts
readme.md

readme.md

read_lines

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 https://raw.githubusercontent.com/johnsonjo4531/read_lines/v2.1.0/examples/cat.ts mobydick.txt

Deno's cat example

$ time deno -A https://deno.land/std@v0.3.4/examples/cat.ts mobydick.txt

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

$ curl https://www.gutenberg.org/files/2701/2701-0.txt -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 https://raw.githubusercontent.com/johnsonjo4531/read_lines/v2.1.0/examples/input.ts

Here's an example run of the program

$ deno https://raw.githubusercontent.com/johnsonjo4531/read_lines/v2.1.0/examples/input.ts
-- DENO ADDER --
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.