summaryrefslogtreecommitdiff
path: root/std/io
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-06-12 20:23:38 +0100
committerGitHub <noreply@github.com>2020-06-12 15:23:38 -0400
commit1fff6f55c3ba98a10018c6d374795e612061e9b6 (patch)
tree12074b6d44736b11513d857e437f9e30a6bf65a4 /std/io
parent26bf56afdaf16634ffbaa23684faf3a44cc10f62 (diff)
refactor: Don't destructure the Deno namespace (#6268)
Diffstat (limited to 'std/io')
-rw-r--r--std/io/bufio_test.ts19
-rw-r--r--std/io/ioutil_test.ts8
-rw-r--r--std/io/readers.ts12
-rw-r--r--std/io/readers_test.ts13
-rw-r--r--std/io/util.ts9
-rw-r--r--std/io/util_test.ts7
-rw-r--r--std/io/writers_test.ts5
7 files changed, 29 insertions, 44 deletions
diff --git a/std/io/bufio_test.ts b/std/io/bufio_test.ts
index 92119e4db..2a32ba135 100644
--- a/std/io/bufio_test.ts
+++ b/std/io/bufio_test.ts
@@ -2,9 +2,6 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-
-const { Buffer } = Deno;
-type Reader = Deno.Reader;
import { assert, assertEquals, fail } from "../testing/asserts.ts";
import {
BufReader,
@@ -47,11 +44,11 @@ Deno.test("bufioReaderSimple", async function (): Promise<void> {
interface ReadMaker {
name: string;
- fn: (r: Reader) => Reader;
+ fn: (r: Deno.Reader) => Deno.Reader;
}
const readMakers: ReadMaker[] = [
- { name: "full", fn: (r): Reader => r },
+ { name: "full", fn: (r): Deno.Reader => r },
{
name: "byte",
fn: (r): iotest.OneByteReader => new iotest.OneByteReader(r),
@@ -190,7 +187,7 @@ const testInputrn = encoder.encode(
const testOutput = encoder.encode("0123456789abcdefghijklmnopqrstuvwxy");
// TestReader wraps a Uint8Array and returns reads of a specific length.
-class TestReader implements Reader {
+class TestReader implements Deno.Reader {
constructor(private data: Uint8Array, private stride: number) {}
read(buf: Uint8Array): Promise<number | null> {
@@ -337,7 +334,7 @@ Deno.test("bufioWriter", async function (): Promise<void> {
data[i] = charCode(" ") + (i % (charCode("~") - charCode(" ")));
}
- const w = new Buffer();
+ const w = new Deno.Buffer();
for (const nwrite of bufsizes) {
for (const bs of bufsizes) {
// Write nwrite bytes using buffer size bs.
@@ -371,7 +368,7 @@ Deno.test("bufioWriterSync", function (): void {
data[i] = charCode(" ") + (i % (charCode("~") - charCode(" ")));
}
- const w = new Buffer();
+ const w = new Deno.Buffer();
for (const nwrite of bufsizes) {
for (const bs of bufsizes) {
// Write nwrite bytes using buffer size bs.
@@ -401,7 +398,7 @@ Deno.test("bufReaderReadFull", async function (): Promise<void> {
const enc = new TextEncoder();
const dec = new TextDecoder();
const text = "Hello World";
- const data = new Buffer(enc.encode(text));
+ const data = new Deno.Buffer(enc.encode(text));
const bufr = new BufReader(data, 3);
{
const buf = new Uint8Array(6);
@@ -426,7 +423,7 @@ Deno.test("bufReaderReadFull", async function (): Promise<void> {
Deno.test("readStringDelimAndLines", async function (): Promise<void> {
const enc = new TextEncoder();
- const data = new Buffer(
+ const data = new Deno.Buffer(
enc.encode("Hello World\tHello World 2\tHello World 3")
);
const chunks_ = [];
@@ -438,7 +435,7 @@ Deno.test("readStringDelimAndLines", async function (): Promise<void> {
assertEquals(chunks_.length, 3);
assertEquals(chunks_, ["Hello World", "Hello World 2", "Hello World 3"]);
- const linesData = new Buffer(enc.encode("0\n1\n2\n3\n4\n5\n6\n7\n8\n9"));
+ const linesData = new Deno.Buffer(enc.encode("0\n1\n2\n3\n4\n5\n6\n7\n8\n9"));
const lines_ = [];
for await (const l of readLines(linesData)) {
diff --git a/std/io/ioutil_test.ts b/std/io/ioutil_test.ts
index 977c7022c..dfdda23fb 100644
--- a/std/io/ioutil_test.ts
+++ b/std/io/ioutil_test.ts
@@ -1,6 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-const { Buffer } = Deno;
-type Reader = Deno.Reader;
import { assertEquals } from "../testing/asserts.ts";
import {
copyN,
@@ -14,7 +12,7 @@ import { BufReader } from "./bufio.ts";
import { tempFile } from "./util.ts";
import * as path from "../path/mod.ts";
-class BinaryReader implements Reader {
+class BinaryReader implements Deno.Reader {
index = 0;
constructor(private bytes: Uint8Array = new Uint8Array(0)) {}
@@ -73,7 +71,7 @@ Deno.test("testSliceLongToBytes2", function (): void {
});
Deno.test("testCopyN1", async function (): Promise<void> {
- const w = new Buffer();
+ const w = new Deno.Buffer();
const r = new StringReader("abcdefghij");
const n = await copyN(r, w, 3);
assertEquals(n, 3);
@@ -81,7 +79,7 @@ Deno.test("testCopyN1", async function (): Promise<void> {
});
Deno.test("testCopyN2", async function (): Promise<void> {
- const w = new Buffer();
+ const w = new Deno.Buffer();
const r = new StringReader("abcdefghij");
const n = await copyN(r, w, 11);
assertEquals(n, 10);
diff --git a/std/io/readers.ts b/std/io/readers.ts
index d43655263..83115ee19 100644
--- a/std/io/readers.ts
+++ b/std/io/readers.ts
@@ -1,27 +1,23 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-
// Based on https://github.com/golang/go/blob/0452f9460f50f0f0aba18df43dc2b31906fb66cc/src/io/io.go
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-
-type Reader = Deno.Reader;
import { encode } from "../encoding/utf8.ts";
-const { Buffer } = Deno;
/** Reader utility for strings */
-export class StringReader extends Buffer {
+export class StringReader extends Deno.Buffer {
constructor(private readonly s: string) {
super(encode(s).buffer);
}
}
/** Reader utility for combining multiple readers */
-export class MultiReader implements Reader {
- private readonly readers: Reader[];
+export class MultiReader implements Deno.Reader {
+ private readonly readers: Deno.Reader[];
private currentIndex = 0;
- constructor(...readers: Reader[]) {
+ constructor(...readers: Deno.Reader[]) {
this.readers = readers;
}
diff --git a/std/io/readers_test.ts b/std/io/readers_test.ts
index 04e9b7488..d608877c1 100644
--- a/std/io/readers_test.ts
+++ b/std/io/readers_test.ts
@@ -1,11 +1,10 @@
-const { copy, test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import { LimitedReader, MultiReader, StringReader } from "./readers.ts";
import { StringWriter } from "./writers.ts";
import { copyN } from "./ioutil.ts";
import { decode } from "../encoding/utf8.ts";
-test("ioStringReader", async function (): Promise<void> {
+Deno.test("ioStringReader", async function (): Promise<void> {
const r = new StringReader("abcdef");
const res0 = await r.read(new Uint8Array(6));
assertEquals(res0, 6);
@@ -13,7 +12,7 @@ test("ioStringReader", async function (): Promise<void> {
assertEquals(res1, null);
});
-test("ioStringReader", async function (): Promise<void> {
+Deno.test("ioStringReader", async function (): Promise<void> {
const r = new StringReader("abcdef");
const buf = new Uint8Array(3);
const res1 = await r.read(buf);
@@ -27,17 +26,17 @@ test("ioStringReader", async function (): Promise<void> {
assertEquals(decode(buf), "def");
});
-test("ioMultiReader", async function (): Promise<void> {
+Deno.test("ioMultiReader", async function (): Promise<void> {
const r = new MultiReader(new StringReader("abc"), new StringReader("def"));
const w = new StringWriter();
const n = await copyN(r, w, 4);
assertEquals(n, 4);
assertEquals(w.toString(), "abcd");
- await copy(r, w);
+ await Deno.copy(r, w);
assertEquals(w.toString(), "abcdef");
});
-test("ioLimitedReader", async function (): Promise<void> {
+Deno.test("ioLimitedReader", async function (): Promise<void> {
let sr = new StringReader("abc");
let r = new LimitedReader(sr, 2);
let buffer = await Deno.readAll(r);
@@ -55,7 +54,7 @@ test("ioLimitedReader", async function (): Promise<void> {
assertEquals((await Deno.readAll(r)).length, 0);
});
-test("ioLimitedReader", async function (): Promise<void> {
+Deno.test("ioLimitedReader", async function (): Promise<void> {
const rb = new StringReader("abc");
const wb = new StringWriter();
await Deno.copy(new LimitedReader(rb, -1), wb);
diff --git a/std/io/util.ts b/std/io/util.ts
index 47e48a981..22ecb1331 100644
--- a/std/io/util.ts
+++ b/std/io/util.ts
@@ -1,7 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-const { mkdir, open } = Deno;
-type File = Deno.File;
-type Reader = Deno.Reader;
import * as path from "../path/mod.ts";
/**
@@ -36,13 +33,13 @@ export async function tempFile(
prefix?: string;
postfix?: string;
} = { prefix: "", postfix: "" }
-): Promise<{ file: File; filepath: string }> {
+): Promise<{ file: Deno.File; filepath: string }> {
const r = Math.floor(Math.random() * 1000000);
const filepath = path.resolve(
`${dir}/${opts.prefix || ""}${r}${opts.postfix || ""}`
);
- await mkdir(path.dirname(filepath), { recursive: true });
- const file = await open(filepath, {
+ await Deno.mkdir(path.dirname(filepath), { recursive: true });
+ const file = await Deno.open(filepath, {
create: true,
read: true,
write: true,
diff --git a/std/io/util_test.ts b/std/io/util_test.ts
index 68a398bd1..d33a328d6 100644
--- a/std/io/util_test.ts
+++ b/std/io/util_test.ts
@@ -1,10 +1,9 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-const { remove, test } = Deno;
import { assert, assertEquals } from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
import { copyBytes, tempFile } from "./util.ts";
-test("[io/tuil] copyBytes", function (): void {
+Deno.test("[io/tuil] copyBytes", function (): void {
const dst = new Uint8Array(4);
dst.fill(0);
@@ -38,7 +37,7 @@ test("[io/tuil] copyBytes", function (): void {
assertEquals(dst, Uint8Array.of(3, 4, 0, 0));
});
-test({
+Deno.test({
name: "[io/util] tempfile",
fn: async function (): Promise<void> {
const f = await tempFile(".", {
@@ -48,6 +47,6 @@ test({
const base = path.basename(f.filepath);
assert(!!base.match(/^prefix-.+?-postfix$/));
f.file.close();
- await remove(f.filepath);
+ await Deno.remove(f.filepath);
},
});
diff --git a/std/io/writers_test.ts b/std/io/writers_test.ts
index f27885f81..13b95a8d5 100644
--- a/std/io/writers_test.ts
+++ b/std/io/writers_test.ts
@@ -1,15 +1,14 @@
-const { copy, test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import { StringWriter } from "./writers.ts";
import { StringReader } from "./readers.ts";
import { copyN } from "./ioutil.ts";
-test("ioStringWriter", async function (): Promise<void> {
+Deno.test("ioStringWriter", async function (): Promise<void> {
const w = new StringWriter("base");
const r = new StringReader("0123456789");
await copyN(r, w, 4);
assertEquals(w.toString(), "base0123");
- await copy(r, w);
+ await Deno.copy(r, w);
assertEquals(w.toString(), "base0123456789");
});