summaryrefslogtreecommitdiff
path: root/io
diff options
context:
space:
mode:
authorYusuke Sakurai <kerokerokerop@gmail.com>2019-05-15 04:19:12 +0900
committerRyan Dahl <ry@tinyclouds.org>2019-05-14 15:19:11 -0400
commite3e9269c76299df99975e17a04b4d1b1ca39dfcb (patch)
treec0bab4773a25589edaea12287c6a8422bd5208f1 /io
parenta3de8c3d8a376049a37f8193c8538acc0d7a88f3 (diff)
feat: ws client (denoland/deno_std#394)
Original: https://github.com/denoland/deno_std/commit/782e3f690ffb9ee0dd89a5a64a3f2b753899719b
Diffstat (limited to 'io')
-rw-r--r--io/bufio.ts10
1 files changed, 10 insertions, 0 deletions
diff --git a/io/bufio.ts b/io/bufio.ts
index f057952fe..749a7e8fa 100644
--- a/io/bufio.ts
+++ b/io/bufio.ts
@@ -33,6 +33,11 @@ export class BufReader implements Reader {
private lastCharSize: number;
private err: BufState;
+ /** return new BufReader unless r is BufReader */
+ static create(r: Reader, size = DEFAULT_BUF_SIZE): BufReader {
+ return r instanceof BufReader ? r : new BufReader(r, size);
+ }
+
constructor(rd: Reader, size = DEFAULT_BUF_SIZE) {
if (size < MIN_BUF_SIZE) {
size = MIN_BUF_SIZE;
@@ -368,6 +373,11 @@ export class BufWriter implements Writer {
n: number = 0;
err: null | BufState = null;
+ /** return new BufWriter unless w is BufWriter */
+ static create(w: Writer, size = DEFAULT_BUF_SIZE): BufWriter {
+ return w instanceof BufWriter ? w : new BufWriter(w, size);
+ }
+
constructor(private wr: Writer, size = DEFAULT_BUF_SIZE) {
if (size <= 0) {
size = DEFAULT_BUF_SIZE;