1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

refactor: rename sync io interfaces (#4945)

This commit renames sync io interfaces:
* SyncReader -> ReaderSync
* SyncWriter -> WriterSync
* SyncSeeker -> SeekerSync
This commit is contained in:
Bartek Iwańczuk 2020-04-28 13:23:30 +02:00 committed by GitHub
parent b980b26d85
commit 2cb875bcfb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 46 deletions

View file

@ -4,7 +4,7 @@
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
// https://github.com/golang/go/blob/master/LICENSE
import { Reader, Writer, EOF, SyncReader, SyncWriter } from "./io.ts";
import { Reader, Writer, EOF, ReaderSync, WriterSync } from "./io.ts";
import { assert } from "./util.ts";
import { TextDecoder } from "./web/text_encoding.ts";
@ -27,7 +27,7 @@ function copyBytes(dst: Uint8Array, src: Uint8Array, off = 0): number {
return src.byteLength;
}
export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
export class Buffer implements Reader, ReaderSync, Writer, WriterSync {
#buf: Uint8Array; // contents are the bytes buf[off : len(buf)]
#off = 0; // read at buf[off], write at buf[buf.byteLength]
@ -180,7 +180,7 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
}
}
readFromSync(r: SyncReader): number {
readFromSync(r: ReaderSync): number {
let n = 0;
while (true) {
try {
@ -206,7 +206,7 @@ export async function readAll(r: Reader): Promise<Uint8Array> {
return buf.bytes();
}
export function readAllSync(r: SyncReader): Uint8Array {
export function readAllSync(r: ReaderSync): Uint8Array {
const buf = new Buffer();
buf.readFromSync(r);
return buf.bytes();
@ -219,7 +219,7 @@ export async function writeAll(w: Writer, arr: Uint8Array): Promise<void> {
}
}
export function writeAllSync(w: SyncWriter, arr: Uint8Array): void {
export function writeAllSync(w: WriterSync, arr: Uint8Array): void {
let nwritten = 0;
while (nwritten < arr.length) {
nwritten += w.writeSync(arr.subarray(nwritten));

View file

@ -46,9 +46,9 @@ export {
iterSync,
SeekMode,
Reader,
SyncReader,
ReaderSync,
Writer,
SyncWriter,
WriterSync,
Closer,
Seeker,
} from "./io.ts";

View file

@ -6,9 +6,9 @@ import {
Seeker,
Closer,
SeekMode,
SyncReader,
SyncWriter,
SyncSeeker,
ReaderSync,
WriterSync,
SeekerSync,
} from "./io.ts";
import { close } from "./ops/resources.ts";
import { read, readSync, write, writeSync } from "./ops/io.ts";
@ -60,11 +60,11 @@ export function create(path: string): Promise<File> {
export class File
implements
Reader,
SyncReader,
ReaderSync,
Writer,
SyncWriter,
WriterSync,
Seeker,
SyncSeeker,
SeekerSync,
Closer {
constructor(readonly rid: number) {}
@ -97,7 +97,7 @@ export class File
}
}
class Stdin implements Reader, SyncReader, Closer {
class Stdin implements Reader, ReaderSync, Closer {
readonly rid: number;
constructor() {
this.rid = 0;
@ -116,7 +116,7 @@ class Stdin implements Reader, SyncReader, Closer {
}
}
class Stdout implements Writer, SyncWriter, Closer {
class Stdout implements Writer, WriterSync, Closer {
readonly rid: number;
constructor() {
this.rid = 1;
@ -135,7 +135,7 @@ class Stdout implements Writer, SyncWriter, Closer {
}
}
export class Stderr implements Writer, SyncWriter, Closer {
export class Stderr implements Writer, WriterSync, Closer {
readonly rid: number;
constructor() {
this.rid = 2;

View file

@ -22,7 +22,7 @@ export interface Reader {
read(p: Uint8Array): Promise<number | EOF>;
}
export interface SyncReader {
export interface ReaderSync {
readSync(p: Uint8Array): number | EOF;
}
@ -32,7 +32,7 @@ export interface Writer {
write(p: Uint8Array): Promise<number>;
}
export interface SyncWriter {
export interface WriterSync {
writeSync(p: Uint8Array): number;
}
@ -48,7 +48,7 @@ export interface Seeker {
seek(offset: number, whence: SeekMode): Promise<number>;
}
export interface SyncSeeker {
export interface SeekerSync {
seekSync(offset: number, whence: SeekMode): number;
}
@ -93,7 +93,7 @@ export async function* iter(
}
export function* iterSync(
r: SyncReader,
r: ReaderSync,
options?: {
bufSize?: number;
}

View file

@ -395,7 +395,7 @@ declare namespace Deno {
read(p: Uint8Array): Promise<number | EOF>;
}
export interface SyncReader {
export interface ReaderSync {
/** Reads up to `p.byteLength` bytes into `p`. It resolves to the number
* of bytes read (`0` < `n` <= `p.byteLength`) and rejects if any error
* encountered. Even if `read()` returns `n` < `p.byteLength`, it may use
@ -414,7 +414,7 @@ declare namespace Deno {
*
* Implementations should not retain a reference to `p`.
*
* Use Deno.iterSync() to turn a SyncReader into an Iterator.
* Use Deno.iterSync() to turn a ReaderSync into an Iterator.
*/
readSync(p: Uint8Array): number | EOF;
}
@ -432,7 +432,7 @@ declare namespace Deno {
write(p: Uint8Array): Promise<number>;
}
export interface SyncWriter {
export interface WriterSync {
/** Writes `p.byteLength` bytes from `p` to the underlying data
* stream. It returns the number of bytes written from `p` (`0` <= `n`
* <= `p.byteLength`) and any error encountered that caused the write to
@ -464,7 +464,7 @@ declare namespace Deno {
seek(offset: number, whence: SeekMode): Promise<number>;
}
export interface SyncSeeker {
export interface SeekerSync {
/** Seek sets the offset for the next `readSync()` or `writeSync()` to
* offset, interpreted according to `whence`: `Start` means relative
* to the start of the file, `Current` means relative to the current
@ -533,7 +533,7 @@ declare namespace Deno {
}
): AsyncIterableIterator<Uint8Array>;
/** Turns a SyncReader, `r`, into an iterator.
/** Turns a ReaderSync, `r`, into an iterator.
*
* let f = Deno.openSync("/etc/passwd");
* for (const chunk of Deno.iterSync(reader)) {
@ -559,7 +559,7 @@ declare namespace Deno {
* next iteration will overwrite contents of previously returned chunk.
*/
export function iterSync(
r: SyncReader,
r: ReaderSync,
options?: {
bufSize?: number;
}
@ -733,11 +733,11 @@ declare namespace Deno {
export class File
implements
Reader,
SyncReader,
ReaderSync,
Writer,
SyncWriter,
WriterSync,
Seeker,
SyncSeeker,
SeekerSync,
Closer {
readonly rid: number;
constructor(rid: number);
@ -751,11 +751,11 @@ declare namespace Deno {
}
/** A handle for `stdin`. */
export const stdin: Reader & SyncReader & Closer & { rid: number };
export const stdin: Reader & ReaderSync & Closer & { rid: number };
/** A handle for `stdout`. */
export const stdout: Writer & SyncWriter & Closer & { rid: number };
export const stdout: Writer & WriterSync & Closer & { rid: number };
/** A handle for `stderr`. */
export const stderr: Writer & SyncWriter & Closer & { rid: number };
export const stderr: Writer & WriterSync & Closer & { rid: number };
export interface OpenOptions {
/** Sets the option for read access. This option, when `true`, means that the
@ -831,7 +831,7 @@ declare namespace Deno {
* of ArrayBuffer.
*
* Based on [Go Buffer](https://golang.org/pkg/bytes/#Buffer). */
export class Buffer implements Reader, SyncReader, Writer, SyncWriter {
export class Buffer implements Reader, ReaderSync, Writer, WriterSync {
constructor(ab?: ArrayBuffer);
/** Returns a slice holding the unread portion of the buffer.
*
@ -892,7 +892,7 @@ declare namespace Deno {
*
* Based on Go Lang's
* [Buffer.ReadFrom](https://golang.org/pkg/bytes/#Buffer.ReadFrom). */
readFromSync(r: SyncReader): number;
readFromSync(r: ReaderSync): number;
}
/** Read Reader `r` until end of file (`Deno.EOF`) and resolve to the content
@ -931,7 +931,7 @@ declare namespace Deno {
* const reader = new Deno.Buffer(myData.buffer as ArrayBuffer);
* const bufferContent = Deno.readAllSync(reader);
*/
export function readAllSync(r: SyncReader): Uint8Array;
export function readAllSync(r: ReaderSync): Uint8Array;
/** Write all the content of the array buffer (`arr`) to the writer (`w`).
*
@ -972,7 +972,7 @@ declare namespace Deno {
* Deno.writeAllSync(writer, contentBytes);
* console.log(writer.bytes().length); // 11
*/
export function writeAllSync(w: SyncWriter, arr: Uint8Array): void;
export function writeAllSync(w: WriterSync, arr: Uint8Array): void;
export interface MkdirOptions {
/** Defaults to `false`. If set to `true`, means that any intermediate

View file

@ -128,7 +128,7 @@ unitTest(async function readerIterSync(): Promise<void> {
// ref: https://github.com/denoland/deno/issues/2330
const encoder = new TextEncoder();
class TestReader implements Deno.SyncReader {
class TestReader implements Deno.ReaderSync {
#offset = 0;
#buf: Uint8Array;

View file

@ -5,7 +5,7 @@
type Reader = Deno.Reader;
type Writer = Deno.Writer;
type SyncWriter = Deno.SyncWriter;
type WriterSync = Deno.WriterSync;
import { charCode, copyBytes } from "./util.ts";
import { assert } from "../testing/asserts.ts";
@ -524,17 +524,17 @@ export class BufWriter extends AbstractBufBase implements Writer {
}
}
/** BufWriterSync implements buffering for a deno.SyncWriter object.
* If an error occurs writing to a SyncWriter, no more data will be
/** BufWriterSync implements buffering for a deno.WriterSync object.
* If an error occurs writing to a WriterSync, no more data will be
* accepted and all subsequent writes, and flush(), will return the error.
* After all data has been written, the client should call the
* flush() method to guarantee all data has been forwarded to
* the underlying deno.SyncWriter.
* the underlying deno.WriterSync.
*/
export class BufWriterSync extends AbstractBufBase implements SyncWriter {
export class BufWriterSync extends AbstractBufBase implements WriterSync {
/** return new BufWriterSync unless writer is BufWriterSync */
static create(
writer: SyncWriter,
writer: WriterSync,
size: number = DEFAULT_BUF_SIZE
): BufWriterSync {
return writer instanceof BufWriterSync
@ -542,7 +542,7 @@ export class BufWriterSync extends AbstractBufBase implements SyncWriter {
: new BufWriterSync(writer, size);
}
constructor(private writer: SyncWriter, size: number = DEFAULT_BUF_SIZE) {
constructor(private writer: WriterSync, size: number = DEFAULT_BUF_SIZE) {
super();
if (size <= 0) {
size = DEFAULT_BUF_SIZE;
@ -553,13 +553,13 @@ export class BufWriterSync extends AbstractBufBase implements SyncWriter {
/** Discards any unflushed buffered data, clears any error, and
* resets buffer to write its output to w.
*/
reset(w: SyncWriter): void {
reset(w: WriterSync): void {
this.err = null;
this.usedBufferBytes = 0;
this.writer = w;
}
/** Flush writes any buffered data to the underlying io.SyncWriter. */
/** Flush writes any buffered data to the underlying io.WriterSync. */
flush(): void {
if (this.err !== null) throw this.err;
if (this.usedBufferBytes === 0) return;