Skip to content

Commit

Permalink
Initial Commit 🚀
Browse files Browse the repository at this point in the history
Switched repos from the old depracated repo: https://github.com/johnsonjo4531/read_lines
  • Loading branch information
johnsonjo4531 committed May 22, 2021
0 parents commit cfc0e04
Show file tree
Hide file tree
Showing 15 changed files with 4,698 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,html,css,json,md,vue,scss,ejs,ts,tsx,jsx,graphql}]
charset = utf-8
indent_style = tab
indent_size = 2

[makefile]
indent_style = tab
indent_size = 4
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mobydick.txt
test.txt
example.txt
index.d.ts
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Deno",
"request": "attach",
"type": "pwa-node",
"cwd": "${workspaceFolder}",
"attachSimplePort": 9229
}
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"deno.import_intellisense_origins": {
"https://deno.land": true
},
"deno.enable": true
}
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2019 johnsonjo4531

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.
7 changes: 7 additions & 0 deletions createTestFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(async () => {
const encoder = new TextEncoder();
const bytes = encoder.encode("a".repeat(10 ** 6));
for (var i = 0; i < 1000; ++i) {
await Deno.stdout.write(bytes);
}
})();
5 changes: 5 additions & 0 deletions dev_deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const { test } = Deno;
export {
assertEquals,
assertThrowsAsync,
} from "https://deno.land/[email protected]/testing/asserts.ts";
25 changes: 25 additions & 0 deletions examples/cat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { readDelim, readLines } from "https://deno.land/[email protected]/io/bufio.ts";

async function* linesBuffer(
reader: Deno.Reader,
): AsyncIterableIterator<Uint8Array> { yield* readDelim(reader, new TextEncoder().encode('\n')) };

async function cat(filenames: string[]): Promise<void> {
const newlinebytes = new TextEncoder().encode("\n");
for (let filename of filenames) {
const file = await Deno.open(filename);
const buffer = new Deno.Buffer();
try {
const file_lines: Uint8Array[] = [];
for await (const line of linesBuffer(file)) {
// you could transform the line buffers here
buffer.write(line);
buffer.write(newlinebytes);
}
Deno.copy(buffer, Deno.stdout);
} finally {
file.close();
}
}
}
cat(Deno.args);
8 changes: 8 additions & 0 deletions examples/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { input } from "../input.ts";

(async () => {
console.log("-- DENO ADDER --");
const num1 = await input("Enter a number: ");
const num2 = await input("Enter another number: ");
console.log(`${num1} + ${num2} = ${Number(num1) + Number(num2)}`);
})();
27 changes: 27 additions & 0 deletions examples/inputCat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { inputReader } from "../input.ts";

async function cat(filenames: string[]): Promise<void> {
const newlinebytes = new TextEncoder().encode("\n");
for (let filename of filenames) {
const file = await Deno.open(filename);
const input = inputReader(file, undefined, {
nullOnEOF: true,
// these are for added speed... at expense of convenience
bufferedRead: true,
bufferedWrite: true
});
const newLine = new TextEncoder().encode("\n")
// const decoder = new TextDecoder();
try {
let line = await input();
while (line !== null) {
line = await input(line, newLine);
}
} finally {
file.close();
}
}
}
await cat(
Deno.args
);
Loading

0 comments on commit cfc0e04

Please sign in to comment.