mirror of
https://github.com/denoland/deno.git
synced 2025-07-30 08:34:35 +00:00
BREAKING: Remove Deno.EOF, use null instead (#4953)
This commit is contained in:
parent
47c2f034e9
commit
678313b176
46 changed files with 329 additions and 325 deletions
|
@ -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, ReaderSync, WriterSync } from "./io.ts";
|
||||
import { Reader, Writer, ReaderSync, WriterSync } from "./io.ts";
|
||||
import { assert } from "./util.ts";
|
||||
import { TextDecoder } from "./web/text_encoding.ts";
|
||||
|
||||
|
@ -91,7 +91,7 @@ export class Buffer implements Reader, ReaderSync, Writer, WriterSync {
|
|||
this.#buf = new Uint8Array(this.#buf.buffer, 0, len);
|
||||
};
|
||||
|
||||
readSync(p: Uint8Array): number | EOF {
|
||||
readSync(p: Uint8Array): number | null {
|
||||
if (this.empty()) {
|
||||
// Buffer is empty, reset to recover space.
|
||||
this.reset();
|
||||
|
@ -99,14 +99,14 @@ export class Buffer implements Reader, ReaderSync, Writer, WriterSync {
|
|||
// this edge case is tested in 'bufferReadEmptyAtEOF' test
|
||||
return 0;
|
||||
}
|
||||
return EOF;
|
||||
return null;
|
||||
}
|
||||
const nread = copyBytes(p, this.#buf.subarray(this.#off));
|
||||
this.#off += nread;
|
||||
return nread;
|
||||
}
|
||||
|
||||
read(p: Uint8Array): Promise<number | EOF> {
|
||||
read(p: Uint8Array): Promise<number | null> {
|
||||
const rr = this.readSync(p);
|
||||
return Promise.resolve(rr);
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ export class Buffer implements Reader, ReaderSync, Writer, WriterSync {
|
|||
this.#reslice(i);
|
||||
const fub = new Uint8Array(this.#buf.buffer, i);
|
||||
const nread = await r.read(fub);
|
||||
if (nread === EOF) {
|
||||
if (nread === null) {
|
||||
return n;
|
||||
}
|
||||
this.#reslice(i + nread);
|
||||
|
@ -188,7 +188,7 @@ export class Buffer implements Reader, ReaderSync, Writer, WriterSync {
|
|||
this.#reslice(i);
|
||||
const fub = new Uint8Array(this.#buf.buffer, i);
|
||||
const nread = r.readSync(fub);
|
||||
if (nread === EOF) {
|
||||
if (nread === null) {
|
||||
return n;
|
||||
}
|
||||
this.#reslice(i + nread);
|
||||
|
|
|
@ -40,7 +40,6 @@ export { read, readSync, write, writeSync } from "./ops/io.ts";
|
|||
export { FsEvent, watchFs } from "./ops/fs_events.ts";
|
||||
export { internalSymbol as internal } from "./internals.ts";
|
||||
export {
|
||||
EOF,
|
||||
copy,
|
||||
iter,
|
||||
iterSync,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import {
|
||||
EOF,
|
||||
Reader,
|
||||
Writer,
|
||||
Seeker,
|
||||
|
@ -76,11 +75,11 @@ export class File
|
|||
return writeSync(this.rid, p);
|
||||
}
|
||||
|
||||
read(p: Uint8Array): Promise<number | EOF> {
|
||||
read(p: Uint8Array): Promise<number | null> {
|
||||
return read(this.rid, p);
|
||||
}
|
||||
|
||||
readSync(p: Uint8Array): number | EOF {
|
||||
readSync(p: Uint8Array): number | null {
|
||||
return readSync(this.rid, p);
|
||||
}
|
||||
|
||||
|
@ -103,11 +102,11 @@ class Stdin implements Reader, ReaderSync, Closer {
|
|||
this.rid = 0;
|
||||
}
|
||||
|
||||
read(p: Uint8Array): Promise<number | EOF> {
|
||||
read(p: Uint8Array): Promise<number | null> {
|
||||
return read(this.rid, p);
|
||||
}
|
||||
|
||||
readSync(p: Uint8Array): number | EOF {
|
||||
readSync(p: Uint8Array): number | null {
|
||||
return readSync(this.rid, p);
|
||||
}
|
||||
|
||||
|
|
13
cli/js/io.ts
13
cli/js/io.ts
|
@ -3,9 +3,6 @@
|
|||
// Documentation liberally lifted from them too.
|
||||
// Thank you! We love Go!
|
||||
|
||||
export const EOF: unique symbol = Symbol("EOF");
|
||||
export type EOF = typeof EOF;
|
||||
|
||||
const DEFAULT_BUFFER_SIZE = 32 * 1024;
|
||||
|
||||
// Seek whence values.
|
||||
|
@ -19,11 +16,11 @@ export enum SeekMode {
|
|||
// Reader is the interface that wraps the basic read() method.
|
||||
// https://golang.org/pkg/io/#Reader
|
||||
export interface Reader {
|
||||
read(p: Uint8Array): Promise<number | EOF>;
|
||||
read(p: Uint8Array): Promise<number | null>;
|
||||
}
|
||||
|
||||
export interface ReaderSync {
|
||||
readSync(p: Uint8Array): number | EOF;
|
||||
readSync(p: Uint8Array): number | null;
|
||||
}
|
||||
|
||||
// Writer is the interface that wraps the basic write() method.
|
||||
|
@ -65,7 +62,7 @@ export async function copy(
|
|||
let gotEOF = false;
|
||||
while (gotEOF === false) {
|
||||
const result = await src.read(b);
|
||||
if (result === EOF) {
|
||||
if (result === null) {
|
||||
gotEOF = true;
|
||||
} else {
|
||||
n += await dst.write(b.subarray(0, result));
|
||||
|
@ -84,7 +81,7 @@ export async function* iter(
|
|||
const b = new Uint8Array(bufSize);
|
||||
while (true) {
|
||||
const result = await r.read(b);
|
||||
if (result === EOF) {
|
||||
if (result === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -102,7 +99,7 @@ export function* iterSync(
|
|||
const b = new Uint8Array(bufSize);
|
||||
while (true) {
|
||||
const result = r.readSync(b);
|
||||
if (result === EOF) {
|
||||
if (result === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
76
cli/js/lib.deno.ns.d.ts
vendored
76
cli/js/lib.deno.ns.d.ts
vendored
|
@ -361,10 +361,6 @@ declare namespace Deno {
|
|||
*/
|
||||
export function umask(mask?: number): number;
|
||||
|
||||
/** **UNSTABLE**: might be removed in favor of `null` (#3932). */
|
||||
export const EOF: unique symbol;
|
||||
export type EOF = typeof EOF;
|
||||
|
||||
export enum SeekMode {
|
||||
Start = 0,
|
||||
Current = 1,
|
||||
|
@ -379,20 +375,21 @@ declare namespace Deno {
|
|||
* available but not `p.byteLength` bytes, `read()` conventionally resolves
|
||||
* to what is available instead of waiting for more.
|
||||
*
|
||||
* When `read()` encounters end-of-file condition, it resolves to
|
||||
* `Deno.EOF` symbol.
|
||||
* When `read()` encounters end-of-file condition, it resolves to EOF
|
||||
* (`null`).
|
||||
*
|
||||
* When `read()` encounters an error, it rejects with an error.
|
||||
*
|
||||
* Callers should always process the `n` > `0` bytes returned before
|
||||
* considering the `EOF`. Doing so correctly handles I/O errors that happen
|
||||
* after reading some bytes and also both of the allowed EOF behaviors.
|
||||
* considering the EOF (`null`). Doing so correctly handles I/O errors that
|
||||
* happen after reading some bytes and also both of the allowed EOF
|
||||
* behaviors.
|
||||
*
|
||||
* Implementations should not retain a reference to `p`.
|
||||
*
|
||||
* Use Deno.iter() to turn a Reader into an AsyncIterator.
|
||||
*/
|
||||
read(p: Uint8Array): Promise<number | EOF>;
|
||||
read(p: Uint8Array): Promise<number | null>;
|
||||
}
|
||||
|
||||
export interface ReaderSync {
|
||||
|
@ -403,20 +400,20 @@ declare namespace Deno {
|
|||
* but not `p.byteLength` bytes, `read()` conventionally returns what is
|
||||
* available instead of waiting for more.
|
||||
*
|
||||
* When `readSync()` encounters end-of-file condition, it returns `Deno.EOF`
|
||||
* symbol.
|
||||
* When `readSync()` encounters end-of-file condition, it returns EOF
|
||||
* (`null`).
|
||||
*
|
||||
* When `readSync()` encounters an error, it throws with an error.
|
||||
*
|
||||
* Callers should always process the `n` > `0` bytes returned before
|
||||
* considering the `EOF`. Doing so correctly handles I/O errors that happen
|
||||
* considering the EOF (`null`). Doing so correctly handles I/O errors that happen
|
||||
* after reading some bytes and also both of the allowed EOF behaviors.
|
||||
*
|
||||
* Implementations should not retain a reference to `p`.
|
||||
*
|
||||
* Use Deno.iterSync() to turn a ReaderSync into an Iterator.
|
||||
*/
|
||||
readSync(p: Uint8Array): number | EOF;
|
||||
readSync(p: Uint8Array): number | null;
|
||||
}
|
||||
|
||||
export interface Writer {
|
||||
|
@ -477,8 +474,8 @@ declare namespace Deno {
|
|||
seekSync(offset: number, whence: SeekMode): number;
|
||||
}
|
||||
|
||||
/** Copies from `src` to `dst` until either `EOF` is reached on `src` or an
|
||||
* error occurs. It resolves to the number of bytes copied or rejects with
|
||||
/** Copies from `src` to `dst` until either EOF (`null`) is read from `src` or
|
||||
* an error occurs. It resolves to the number of bytes copied or rejects with
|
||||
* the first error encountered while copying.
|
||||
*
|
||||
* const source = await Deno.open("my_file.txt");
|
||||
|
@ -486,9 +483,6 @@ declare namespace Deno {
|
|||
* const bytesCopied1 = await Deno.copy(source, Deno.stdout);
|
||||
* const bytesCopied2 = await Deno.copy(source, buffer);
|
||||
*
|
||||
* Because `copy()` is defined to read from `src` until `EOF`, it does not
|
||||
* treat an `EOF` from `read()` as an error to be reported.
|
||||
*
|
||||
* @param src The source to copy from
|
||||
* @param dst The destination to copy to
|
||||
* @param options Can be used to tune size of the buffer. Default size is 32kB
|
||||
|
@ -611,8 +605,11 @@ declare namespace Deno {
|
|||
|
||||
/** Synchronously read from a resource ID (`rid`) into an array buffer (`buffer`).
|
||||
*
|
||||
* Returns either the number of bytes read during the operation or End Of File
|
||||
* (`Symbol(EOF)`) if there was nothing to read.
|
||||
* Returns either the number of bytes read during the operation or EOF
|
||||
* (`null`) if there was nothing more to read.
|
||||
*
|
||||
* It is possible for a read to successfully return with `0` bytes. This does
|
||||
* not indicate EOF.
|
||||
*
|
||||
* // if "/foo/bar.txt" contains the text "hello world":
|
||||
* const file = Deno.openSync("/foo/bar.txt");
|
||||
|
@ -621,12 +618,15 @@ declare namespace Deno {
|
|||
* const text = new TextDecoder().decode(buf); // "hello world"
|
||||
* Deno.close(file.rid);
|
||||
*/
|
||||
export function readSync(rid: number, buffer: Uint8Array): number | EOF;
|
||||
export function readSync(rid: number, buffer: Uint8Array): number | null;
|
||||
|
||||
/** Read from a resource ID (`rid`) into an array buffer (`buffer`).
|
||||
*
|
||||
* Resolves to either the number of bytes read during the operation or End Of
|
||||
* File (`Symbol(EOF)`) if there was nothing to read.
|
||||
* Resolves to either the number of bytes read during the operation or EOF
|
||||
* (`null`) if there was nothing more to read.
|
||||
*
|
||||
* It is possible for a read to successfully return with `0` bytes. This does
|
||||
* not indicate EOF.
|
||||
*
|
||||
* // if "/foo/bar.txt" contains the text "hello world":
|
||||
* const file = await Deno.open("/foo/bar.txt");
|
||||
|
@ -635,7 +635,7 @@ declare namespace Deno {
|
|||
* const text = new TextDecoder().decode(buf); // "hello world"
|
||||
* Deno.close(file.rid);
|
||||
*/
|
||||
export function read(rid: number, buffer: Uint8Array): Promise<number | EOF>;
|
||||
export function read(rid: number, buffer: Uint8Array): Promise<number | null>;
|
||||
|
||||
/** Synchronously write to the resource ID (`rid`) the contents of the array
|
||||
* buffer (`data`).
|
||||
|
@ -743,8 +743,8 @@ declare namespace Deno {
|
|||
constructor(rid: number);
|
||||
write(p: Uint8Array): Promise<number>;
|
||||
writeSync(p: Uint8Array): number;
|
||||
read(p: Uint8Array): Promise<number | EOF>;
|
||||
readSync(p: Uint8Array): number | EOF;
|
||||
read(p: Uint8Array): Promise<number | null>;
|
||||
readSync(p: Uint8Array): number | null;
|
||||
seek(offset: number, whence: SeekMode): Promise<number>;
|
||||
seekSync(offset: number, whence: SeekMode): number;
|
||||
close(): void;
|
||||
|
@ -863,12 +863,12 @@ declare namespace Deno {
|
|||
reset(): void;
|
||||
/** Reads the next `p.length` bytes from the buffer or until the buffer is
|
||||
* drained. Returns the number of bytes read. If the buffer has no data to
|
||||
* return, the return is `Deno.EOF`. */
|
||||
readSync(p: Uint8Array): number | EOF;
|
||||
* return, the return is EOF (`null`). */
|
||||
readSync(p: Uint8Array): number | null;
|
||||
/** Reads the next `p.length` bytes from the buffer or until the buffer is
|
||||
* drained. Resolves to the number of bytes read. If the buffer has no
|
||||
* data to return, resolves to `Deno.EOF`. */
|
||||
read(p: Uint8Array): Promise<number | EOF>;
|
||||
* data to return, resolves to EOF (`null`). */
|
||||
read(p: Uint8Array): Promise<number | null>;
|
||||
writeSync(p: Uint8Array): number;
|
||||
write(p: Uint8Array): Promise<number>;
|
||||
/** Grows the buffer's capacity, if necessary, to guarantee space for
|
||||
|
@ -879,14 +879,14 @@ declare namespace Deno {
|
|||
* Based on Go Lang's
|
||||
* [Buffer.Grow](https://golang.org/pkg/bytes/#Buffer.Grow). */
|
||||
grow(n: number): void;
|
||||
/** Reads data from `r` until `Deno.EOF` and appends it to the buffer,
|
||||
/** Reads data from `r` until EOF (`null`) and appends it to the buffer,
|
||||
* growing the buffer as needed. It resolves to the number of bytes read.
|
||||
* If the buffer becomes too large, `.readFrom()` will reject with an error.
|
||||
*
|
||||
* Based on Go Lang's
|
||||
* [Buffer.ReadFrom](https://golang.org/pkg/bytes/#Buffer.ReadFrom). */
|
||||
readFrom(r: Reader): Promise<number>;
|
||||
/** Reads data from `r` until `Deno.EOF` and appends it to the buffer,
|
||||
/** Reads data from `r` until EOF (`null`) and appends it to the buffer,
|
||||
* growing the buffer as needed. It returns the number of bytes read. If the
|
||||
* buffer becomes too large, `.readFromSync()` will throw an error.
|
||||
*
|
||||
|
@ -895,8 +895,8 @@ declare namespace Deno {
|
|||
readFromSync(r: ReaderSync): number;
|
||||
}
|
||||
|
||||
/** Read Reader `r` until end of file (`Deno.EOF`) and resolve to the content
|
||||
* as `Uint8Array`.
|
||||
/** Read Reader `r` until EOF (`null`) and resolve to the content as
|
||||
* Uint8Array`.
|
||||
*
|
||||
* // Example from stdin
|
||||
* const stdinContent = await Deno.readAll(Deno.stdin);
|
||||
|
@ -914,8 +914,8 @@ declare namespace Deno {
|
|||
*/
|
||||
export function readAll(r: Reader): Promise<Uint8Array>;
|
||||
|
||||
/** Synchronously reads Reader `r` until end of file (`Deno.EOF`) and returns
|
||||
* the content as `Uint8Array`.
|
||||
/** Synchronously reads Reader `r` until EOF (`null`) and returns the content
|
||||
* as `Uint8Array`.
|
||||
*
|
||||
* // Example from stdin
|
||||
* const stdinContent = Deno.readAllSync(Deno.stdin);
|
||||
|
@ -2183,13 +2183,13 @@ declare namespace Deno {
|
|||
readonly stderr?: Reader & Closer;
|
||||
/** Resolves to the current status of the process. */
|
||||
status(): Promise<ProcessStatus>;
|
||||
/** Buffer the stdout and return it as `Uint8Array` after `Deno.EOF`.
|
||||
/** Buffer the stdout until EOF and return it as `Uint8Array`.
|
||||
*
|
||||
* You must set stdout to `"piped"` when creating the process.
|
||||
*
|
||||
* This calls `close()` on stdout after its done. */
|
||||
output(): Promise<Uint8Array>;
|
||||
/** Buffer the stderr and return it as `Uint8Array` after `Deno.EOF`.
|
||||
/** Buffer the stderr until EOF and return it as `Uint8Array`.
|
||||
*
|
||||
* You must set stderr to `"piped"` when creating the process.
|
||||
*
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { errors } from "./errors.ts";
|
||||
import { EOF, Reader, Writer, Closer } from "./io.ts";
|
||||
import { Reader, Writer, Closer } from "./io.ts";
|
||||
import { read, write } from "./ops/io.ts";
|
||||
import { close } from "./ops/resources.ts";
|
||||
import * as netOps from "./ops/net.ts";
|
||||
|
@ -40,7 +40,7 @@ export class ConnImpl implements Conn {
|
|||
return write(this.rid, p);
|
||||
}
|
||||
|
||||
read(p: Uint8Array): Promise<number | EOF> {
|
||||
read(p: Uint8Array): Promise<number | null> {
|
||||
return read(this.rid, p);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { sendAsyncMinimal, sendSyncMinimal } from "./dispatch_minimal.ts";
|
||||
import { EOF } from "../io.ts";
|
||||
// TODO(bartlomieju): remove this import and maybe lazy-initialize
|
||||
// OPS_CACHE that belongs only to this module
|
||||
import { OPS_CACHE } from "../runtime.ts";
|
||||
|
@ -10,7 +9,7 @@ import { OPS_CACHE } from "../runtime.ts";
|
|||
let OP_READ = -1;
|
||||
let OP_WRITE = -1;
|
||||
|
||||
export function readSync(rid: number, buffer: Uint8Array): number | EOF {
|
||||
export function readSync(rid: number, buffer: Uint8Array): number | null {
|
||||
if (buffer.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -21,7 +20,7 @@ export function readSync(rid: number, buffer: Uint8Array): number | EOF {
|
|||
if (nread < 0) {
|
||||
throw new Error("read error");
|
||||
} else if (nread == 0) {
|
||||
return EOF;
|
||||
return null;
|
||||
} else {
|
||||
return nread;
|
||||
}
|
||||
|
@ -30,7 +29,7 @@ export function readSync(rid: number, buffer: Uint8Array): number | EOF {
|
|||
export async function read(
|
||||
rid: number,
|
||||
buffer: Uint8Array
|
||||
): Promise<number | EOF> {
|
||||
): Promise<number | null> {
|
||||
if (buffer.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -41,7 +40,7 @@ export async function read(
|
|||
if (nread < 0) {
|
||||
throw new Error("read error");
|
||||
} else if (nread == 0) {
|
||||
return EOF;
|
||||
return null;
|
||||
} else {
|
||||
return nread;
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ async function empty(buf: Buffer, s: string, fub: Uint8Array): Promise<void> {
|
|||
check(buf, s);
|
||||
while (true) {
|
||||
const r = await buf.read(fub);
|
||||
if (r === Deno.EOF) {
|
||||
if (r === null) {
|
||||
break;
|
||||
}
|
||||
s = s.slice(r);
|
||||
|
@ -231,8 +231,7 @@ unitTest(async function bufferTestGrow(): Promise<void> {
|
|||
for (const growLen of [0, 100, 1000, 10000, 100000]) {
|
||||
const buf = new Buffer(xBytes.buffer as ArrayBuffer);
|
||||
// If we read, this affects buf.off, which is good to test.
|
||||
const result = await buf.read(tmp);
|
||||
const nread = result === Deno.EOF ? 0 : result;
|
||||
const nread = (await buf.read(tmp)) ?? 0;
|
||||
buf.grow(growLen);
|
||||
const yBytes = repeat("y", growLen);
|
||||
await buf.write(yBytes);
|
||||
|
|
|
@ -101,13 +101,13 @@ unitTest(async function readerIter(): Promise<void> {
|
|||
this.#buf = new Uint8Array(encoder.encode(s));
|
||||
}
|
||||
|
||||
read(p: Uint8Array): Promise<number | Deno.EOF> {
|
||||
read(p: Uint8Array): Promise<number | null> {
|
||||
const n = Math.min(p.byteLength, this.#buf.byteLength - this.#offset);
|
||||
p.set(this.#buf.slice(this.#offset, this.#offset + n));
|
||||
this.#offset += n;
|
||||
|
||||
if (n === 0) {
|
||||
return Promise.resolve(Deno.EOF);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
return Promise.resolve(n);
|
||||
|
@ -136,13 +136,13 @@ unitTest(async function readerIterSync(): Promise<void> {
|
|||
this.#buf = new Uint8Array(encoder.encode(s));
|
||||
}
|
||||
|
||||
readSync(p: Uint8Array): number | Deno.EOF {
|
||||
readSync(p: Uint8Array): number | null {
|
||||
const n = Math.min(p.byteLength, this.#buf.byteLength - this.#offset);
|
||||
p.set(this.#buf.slice(this.#offset, this.#offset + n));
|
||||
this.#offset += n;
|
||||
|
||||
if (n === 0) {
|
||||
return Deno.EOF;
|
||||
return null;
|
||||
}
|
||||
|
||||
return n;
|
||||
|
|
|
@ -19,7 +19,7 @@ function spyRead(obj: Deno.Buffer): Spy {
|
|||
|
||||
const orig = obj.read.bind(obj);
|
||||
|
||||
obj.read = (p: Uint8Array): Promise<number | Deno.EOF> => {
|
||||
obj.read = (p: Uint8Array): Promise<number | null> => {
|
||||
spy.calls++;
|
||||
return orig(p);
|
||||
};
|
||||
|
|
|
@ -179,10 +179,10 @@ unitTest({ perms: { net: true } }, async function netTcpDialListen(): Promise<
|
|||
assertEquals(3, buf[2]);
|
||||
assert(conn.rid > 0);
|
||||
|
||||
assert(readResult !== Deno.EOF);
|
||||
assert(readResult !== null);
|
||||
|
||||
const readResult2 = await conn.read(buf);
|
||||
assertEquals(Deno.EOF, readResult2);
|
||||
assertEquals(readResult2, null);
|
||||
|
||||
listener.close();
|
||||
conn.close();
|
||||
|
@ -214,10 +214,10 @@ unitTest(
|
|||
assertEquals(3, buf[2]);
|
||||
assert(conn.rid > 0);
|
||||
|
||||
assert(readResult !== Deno.EOF);
|
||||
assert(readResult !== null);
|
||||
|
||||
const readResult2 = await conn.read(buf);
|
||||
assertEquals(Deno.EOF, readResult2);
|
||||
assertEquals(readResult2, null);
|
||||
|
||||
listener.close();
|
||||
conn.close();
|
||||
|
@ -358,10 +358,10 @@ unitTest(
|
|||
assertEquals(3, buf[2]);
|
||||
assert(conn.rid > 0);
|
||||
|
||||
assert(readResult !== Deno.EOF);
|
||||
assert(readResult !== null);
|
||||
|
||||
const readResult2 = await conn.read(buf);
|
||||
assertEquals(Deno.EOF, readResult2);
|
||||
assertEquals(readResult2, null);
|
||||
|
||||
listener.close();
|
||||
conn.close();
|
||||
|
@ -396,7 +396,7 @@ unitTest(
|
|||
closeReadDeferred.resolve();
|
||||
const buf = new Uint8Array(1024);
|
||||
const readResult = await conn.read(buf);
|
||||
assertEquals(Deno.EOF, readResult); // with immediate EOF
|
||||
assertEquals(readResult, null); // with immediate EOF
|
||||
// Ensure closeRead does not impact write
|
||||
await conn.write(new Uint8Array([4, 5, 6]));
|
||||
await closeDeferred;
|
||||
|
@ -523,7 +523,7 @@ unitTest(
|
|||
try {
|
||||
while (true) {
|
||||
const nread = await conn.read(p);
|
||||
if (nread === Deno.EOF) {
|
||||
if (nread === null) {
|
||||
break;
|
||||
}
|
||||
await conn.write(new Uint8Array([1, 2, 3]));
|
||||
|
|
|
@ -154,14 +154,14 @@ unitTest({ perms: { run: true } }, async function runStdoutPiped(): Promise<
|
|||
|
||||
const data = new Uint8Array(10);
|
||||
let r = await p.stdout!.read(data);
|
||||
if (r === Deno.EOF) {
|
||||
throw new Error("p.stdout.read(...) should not be EOF");
|
||||
if (r === null) {
|
||||
throw new Error("p.stdout.read(...) should not be null");
|
||||
}
|
||||
assertEquals(r, 5);
|
||||
const s = new TextDecoder().decode(data.subarray(0, r));
|
||||
assertEquals(s, "hello");
|
||||
r = await p.stdout!.read(data);
|
||||
assertEquals(r, Deno.EOF);
|
||||
assertEquals(r, null);
|
||||
p.stdout!.close();
|
||||
|
||||
const status = await p.status();
|
||||
|
@ -183,14 +183,14 @@ unitTest({ perms: { run: true } }, async function runStderrPiped(): Promise<
|
|||
|
||||
const data = new Uint8Array(10);
|
||||
let r = await p.stderr!.read(data);
|
||||
if (r === Deno.EOF) {
|
||||
throw new Error("p.stderr.read should not return EOF here");
|
||||
if (r === null) {
|
||||
throw new Error("p.stderr.read should not return null here");
|
||||
}
|
||||
assertEquals(r, 5);
|
||||
const s = new TextDecoder().decode(data.subarray(0, r));
|
||||
assertEquals(s, "hello");
|
||||
r = await p.stderr!.read(data);
|
||||
assertEquals(r, Deno.EOF);
|
||||
assertEquals(r, null);
|
||||
p.stderr!.close();
|
||||
|
||||
const status = await p.status();
|
||||
|
@ -313,7 +313,7 @@ unitTest({ perms: { run: true } }, async function runClose(): Promise<void> {
|
|||
|
||||
const data = new Uint8Array(10);
|
||||
const r = await p.stderr!.read(data);
|
||||
assertEquals(r, Deno.EOF);
|
||||
assertEquals(r, null);
|
||||
p.stderr!.close();
|
||||
});
|
||||
|
||||
|
|
|
@ -191,7 +191,7 @@ unitTest(
|
|||
await w.flush();
|
||||
const tpr = new TextProtoReader(r);
|
||||
const statusLine = await tpr.readLine();
|
||||
assert(statusLine !== Deno.EOF, `line must be read: ${String(statusLine)}`);
|
||||
assert(statusLine !== null, `line must be read: ${String(statusLine)}`);
|
||||
const m = statusLine.match(/^(.+?) (.+?) (.+?)$/);
|
||||
assert(m !== null, "must be matched");
|
||||
const [_, proto, status, ok] = m;
|
||||
|
@ -199,7 +199,7 @@ unitTest(
|
|||
assertEquals(status, "200");
|
||||
assertEquals(ok, "OK");
|
||||
const headers = await tpr.readMIMEHeader();
|
||||
assert(headers !== Deno.EOF);
|
||||
assert(headers !== null);
|
||||
const contentLength = parseInt(headers.get("content-length")!);
|
||||
const bodyBuf = new Uint8Array(contentLength);
|
||||
await r.readFull(bodyBuf);
|
||||
|
@ -225,7 +225,7 @@ unitTest(
|
|||
let writer = new BufWriter(conn);
|
||||
let reader = new TextProtoReader(new BufReader(conn));
|
||||
|
||||
let line: string | Deno.EOF = (await reader.readLine()) as string;
|
||||
let line: string | null = (await reader.readLine()) as string;
|
||||
assert(line.startsWith("220"));
|
||||
|
||||
await writer.write(encoder.encode(`EHLO ${hostname}\r\n`));
|
||||
|
|
|
@ -220,7 +220,7 @@ class Body
|
|||
return decoder.decode(ab);
|
||||
}
|
||||
|
||||
read(p: Uint8Array): Promise<number | io.EOF> {
|
||||
read(p: Uint8Array): Promise<number | null> {
|
||||
this.#bodyUsed = true;
|
||||
return read(this.#rid, p);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue