Skip to content

Commit cfc0e04

Browse files
committed
Initial Commit 🚀
Switched repos from the old depracated repo: https://github.com/johnsonjo4531/read_lines
0 parents  commit cfc0e04

File tree

15 files changed

+4698
-0
lines changed

15 files changed

+4698
-0
lines changed

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
11+
# Matches multiple files with brace expansion notation
12+
# Set default charset
13+
[*.{js,html,css,json,md,vue,scss,ejs,ts,tsx,jsx,graphql}]
14+
charset = utf-8
15+
indent_style = tab
16+
indent_size = 2
17+
18+
[makefile]
19+
indent_style = tab
20+
indent_size = 4

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mobydick.txt
2+
test.txt
3+
example.txt
4+
index.d.ts

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch Deno",
9+
"request": "attach",
10+
"type": "pwa-node",
11+
"cwd": "${workspaceFolder}",
12+
"attachSimplePort": 9229
13+
}
14+
]
15+
}

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"deno.import_intellisense_origins": {
3+
"https://deno.land": true
4+
},
5+
"deno.enable": true
6+
}

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2019 johnsonjo4531
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

createTestFile.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(async () => {
2+
const encoder = new TextEncoder();
3+
const bytes = encoder.encode("a".repeat(10 ** 6));
4+
for (var i = 0; i < 1000; ++i) {
5+
await Deno.stdout.write(bytes);
6+
}
7+
})();

dev_deps.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const { test } = Deno;
2+
export {
3+
assertEquals,
4+
assertThrowsAsync,
5+
} from "https://deno.land/[email protected]/testing/asserts.ts";

examples/cat.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { readDelim, readLines } from "https://deno.land/[email protected]/io/bufio.ts";
2+
3+
async function* linesBuffer(
4+
reader: Deno.Reader,
5+
): AsyncIterableIterator<Uint8Array> { yield* readDelim(reader, new TextEncoder().encode('\n')) };
6+
7+
async function cat(filenames: string[]): Promise<void> {
8+
const newlinebytes = new TextEncoder().encode("\n");
9+
for (let filename of filenames) {
10+
const file = await Deno.open(filename);
11+
const buffer = new Deno.Buffer();
12+
try {
13+
const file_lines: Uint8Array[] = [];
14+
for await (const line of linesBuffer(file)) {
15+
// you could transform the line buffers here
16+
buffer.write(line);
17+
buffer.write(newlinebytes);
18+
}
19+
Deno.copy(buffer, Deno.stdout);
20+
} finally {
21+
file.close();
22+
}
23+
}
24+
}
25+
cat(Deno.args);

examples/input.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { input } from "../input.ts";
2+
3+
(async () => {
4+
console.log("-- DENO ADDER --");
5+
const num1 = await input("Enter a number: ");
6+
const num2 = await input("Enter another number: ");
7+
console.log(`${num1} + ${num2} = ${Number(num1) + Number(num2)}`);
8+
})();

examples/inputCat.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { inputReader } from "../input.ts";
2+
3+
async function cat(filenames: string[]): Promise<void> {
4+
const newlinebytes = new TextEncoder().encode("\n");
5+
for (let filename of filenames) {
6+
const file = await Deno.open(filename);
7+
const input = inputReader(file, undefined, {
8+
nullOnEOF: true,
9+
// these are for added speed... at expense of convenience
10+
bufferedRead: true,
11+
bufferedWrite: true
12+
});
13+
const newLine = new TextEncoder().encode("\n")
14+
// const decoder = new TextDecoder();
15+
try {
16+
let line = await input();
17+
while (line !== null) {
18+
line = await input(line, newLine);
19+
}
20+
} finally {
21+
file.close();
22+
}
23+
}
24+
}
25+
await cat(
26+
Deno.args
27+
);

0 commit comments

Comments
 (0)