1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-23 15:16:54 -05:00
denoland-deno/std/io
Kitson Kelly 82aabb657a
feat: add --no-check option (#6456)
This commit adds a "--no-check" option to following subcommands:
- "deno cache"
- "deno info"
- "deno run"
- "deno test"

The "--no-check" options allows to skip type checking step and instead 
directly transpiles TS sources to JS sources. 

This solution uses `ts.transpileModule()` API and is just an interim
solution before implementing it fully in Rust.
2020-07-08 11:26:39 +02:00
..
_iotest.ts BREAKING(std): reorganization (#5087) 2020-05-09 08:34:47 -04:00
bufio.ts fix(std/io): Make BufWriter/BufWriterSync.flush write all chunks (#6269) 2020-06-25 14:17:33 +02:00
bufio_test.ts fix(std/io): Make BufWriter/BufWriterSync.flush write all chunks (#6269) 2020-06-25 14:17:33 +02:00
ioutil.ts feat: add --no-check option (#6456) 2020-07-08 11:26:39 +02:00
ioutil_test.ts refactor: Don't destructure the Deno namespace (#6268) 2020-06-12 15:23:38 -04:00
mod.ts fix(std/io): export streams.ts & added docs (#6535) 2020-06-27 20:20:48 -04:00
readers.ts refactor: Don't destructure the Deno namespace (#6268) 2020-06-12 15:23:38 -04:00
readers_test.ts refactor: Don't destructure the Deno namespace (#6268) 2020-06-12 15:23:38 -04:00
README.md fix(std/io): export streams.ts & added docs (#6535) 2020-06-27 20:20:48 -04:00
streams.ts feat(std/io): add fromStreamReader, fromStreamWriter (#5789) 2020-06-27 16:55:01 -04:00
streams_test.ts feat(std/io): add fromStreamReader, fromStreamWriter (#5789) 2020-06-27 16:55:01 -04:00
util.ts refactor: shift copyBytes and tweak deps to reduce dependencies (#6469) 2020-06-25 06:40:51 -04:00
util_test.ts refactor: shift copyBytes and tweak deps to reduce dependencies (#6469) 2020-06-25 06:40:51 -04:00
writers.ts fix(std/io): BufWriter/StringWriter bug (#6247) 2020-06-12 15:15:29 -04:00
writers_test.ts fix(std/io): Use Deno.test in writers_test (#6273) 2020-06-13 00:10:25 +02:00

std/io

Bufio

Uses:

readLines

Read reader[like file], line by line

import { readLines } from "https://deno.land/std/io/mod.ts";
import * as path from "https://deno.land/std/path/mod.ts";

const filename = path.join(Deno.cwd(), "std/io/README.md");
let fileReader = await Deno.open(filename);

for await (let line of readLines(fileReader)) {
  console.log(line);
}

Output:

# std/io

## readLines

```ts
import * as path from "https://deno.land/std/path/mod.ts";

## Rest of the file

readStringDelim

Read reader[like file] chunk by chunk, splitting based on delimiter.

import { readLines } from "https://deno.land/std/io/mod.ts";
import * as path from "https://deno.land/std/path/mod.ts";

const filename = path.join(Deno.cwd(), "std/io/README.md");
let fileReader = await Deno.open(filename);

for await (let line of readStringDelim(fileReader, "\n")) {
  console.log(line);
}

Output:

# std/io

## readLines

```ts
import * as path from "https://deno.land/std/path/mod.ts";

## Rest of the file

Reader

StringReader

Create a Reader object for string.

import { StringReader } from "https://deno.land/std/io/mod.ts";

const data = new Uint8Array(6);
const r = new StringReader("abcdef");
const res0 = await r.read(data);
const res1 = await r.read(new Uint8Array(6));

// Number of bytes read
console.log(res0); // 6
console.log(res1); // null, no byte left to read. EOL

// text

console.log(new TextDecoder().decode(data)); // abcdef

Output:

6
null
abcdef

Writer

StringWriter

Create a Writer object for string.

import {
  StringWriter,
  StringReader,
  copyN,
} from "https://deno.land/std/io/mod.ts";

const w = new StringWriter("base");
const r = new StringReader("0123456789");
await copyN(r, w, 4); // copy 4 bytes

// Number of bytes read
console.log(w.toString()); //base0123

await Deno.copy(r, w); // copy all
console.log(w.toString()); // base0123456789

Output:

base0123
base0123456789

Streams

fromStreamReader

Creates a Reader from a ReadableStreamDefaultReader

import { fromStreamReader } from "https://deno.land/std/io/mod.ts";
const res = await fetch("https://deno.land");
const file = await Deno.open("./deno.land.html", { create: true, write: true });

const reader = fromStreamReader(res.body!.getReader());
await Deno.copy(reader, file);
file.close();

fromStreamWriter

Creates a Writer from a WritableStreamDefaultWriter

import { fromStreamWriter } from "https://deno.land/std/io/mod.ts";
const file = await Deno.open("./deno.land.html", { read: true });

const writableStream = new WritableStream({
  write(chunk): void {
    console.log(chunk);
  },
});
const writer = fromStreamWriter(writableStream.getWriter());
await Deno.copy(file, writer);
file.close();