mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
better parameter names for a couple functions (#4559)
This commit is contained in:
parent
fa7929ad2c
commit
1c30d755bf
2 changed files with 22 additions and 18 deletions
17
cli/js/lib.deno.ns.d.ts
vendored
17
cli/js/lib.deno.ns.d.ts
vendored
|
@ -649,7 +649,7 @@ declare namespace Deno {
|
|||
*/
|
||||
export function create(path: string): Promise<File>;
|
||||
|
||||
/** Synchronously read from a resource ID (`rid`) into an array buffer.
|
||||
/** 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.
|
||||
|
@ -661,9 +661,9 @@ declare namespace Deno {
|
|||
* const text = new TextDecoder().decode(buf); // "hello world"
|
||||
* Deno.close(file.rid);
|
||||
*/
|
||||
export function readSync(rid: number, p: Uint8Array): number | EOF;
|
||||
export function readSync(rid: number, buffer: Uint8Array): number | EOF;
|
||||
|
||||
/** Read from a resource ID (`rid`) into an array buffer.
|
||||
/** 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.
|
||||
|
@ -675,9 +675,10 @@ declare namespace Deno {
|
|||
* const text = new TextDecoder().decode(buf); // "hello world"
|
||||
* Deno.close(file.rid);
|
||||
*/
|
||||
export function read(rid: number, p: Uint8Array): Promise<number | EOF>;
|
||||
export function read(rid: number, buffer: Uint8Array): Promise<number | EOF>;
|
||||
|
||||
/** Synchronously write to the resource ID (`rid`) the contents of the array buffer.
|
||||
/** Synchronously write to the resource ID (`rid`) the contents of the array
|
||||
* buffer (`data`).
|
||||
*
|
||||
* Returns the number of bytes written.
|
||||
*
|
||||
|
@ -687,9 +688,9 @@ declare namespace Deno {
|
|||
* const bytesWritten = Deno.writeSync(file.rid, data); // 11
|
||||
* Deno.close(file.rid);
|
||||
*/
|
||||
export function writeSync(rid: number, p: Uint8Array): number;
|
||||
export function writeSync(rid: number, data: Uint8Array): number;
|
||||
|
||||
/** Write to the resource ID (`rid`) the contents of the array buffer.
|
||||
/** Write to the resource ID (`rid`) the contents of the array buffer (`data`).
|
||||
*
|
||||
* Resolves to the number of bytes written.
|
||||
*
|
||||
|
@ -699,7 +700,7 @@ declare namespace Deno {
|
|||
* const bytesWritten = await Deno.write(file.rid, data); // 11
|
||||
* Deno.close(file.rid);
|
||||
*/
|
||||
export function write(rid: number, p: Uint8Array): Promise<number>;
|
||||
export function write(rid: number, data: Uint8Array): Promise<number>;
|
||||
|
||||
/** Synchronously seek a resource ID (`rid`) to the given `offset` under mode
|
||||
* given by `whence`. The current position within the resource is returned.
|
||||
|
|
|
@ -10,14 +10,14 @@ import { OPS_CACHE } from "../runtime.ts";
|
|||
let OP_READ = -1;
|
||||
let OP_WRITE = -1;
|
||||
|
||||
export function readSync(rid: number, p: Uint8Array): number | EOF {
|
||||
if (p.length == 0) {
|
||||
export function readSync(rid: number, buffer: Uint8Array): number | EOF {
|
||||
if (buffer.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (OP_READ < 0) {
|
||||
OP_READ = OPS_CACHE["op_read"];
|
||||
}
|
||||
const nread = sendSyncMinimal(OP_READ, rid, p);
|
||||
const nread = sendSyncMinimal(OP_READ, rid, buffer);
|
||||
if (nread < 0) {
|
||||
throw new Error("read error");
|
||||
} else if (nread == 0) {
|
||||
|
@ -27,14 +27,17 @@ export function readSync(rid: number, p: Uint8Array): number | EOF {
|
|||
}
|
||||
}
|
||||
|
||||
export async function read(rid: number, p: Uint8Array): Promise<number | EOF> {
|
||||
if (p.length == 0) {
|
||||
export async function read(
|
||||
rid: number,
|
||||
buffer: Uint8Array
|
||||
): Promise<number | EOF> {
|
||||
if (buffer.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (OP_READ < 0) {
|
||||
OP_READ = OPS_CACHE["op_read"];
|
||||
}
|
||||
const nread = await sendAsyncMinimal(OP_READ, rid, p);
|
||||
const nread = await sendAsyncMinimal(OP_READ, rid, buffer);
|
||||
if (nread < 0) {
|
||||
throw new Error("read error");
|
||||
} else if (nread == 0) {
|
||||
|
@ -44,11 +47,11 @@ export async function read(rid: number, p: Uint8Array): Promise<number | EOF> {
|
|||
}
|
||||
}
|
||||
|
||||
export function writeSync(rid: number, p: Uint8Array): number {
|
||||
export function writeSync(rid: number, data: Uint8Array): number {
|
||||
if (OP_WRITE < 0) {
|
||||
OP_WRITE = OPS_CACHE["op_write"];
|
||||
}
|
||||
const result = sendSyncMinimal(OP_WRITE, rid, p);
|
||||
const result = sendSyncMinimal(OP_WRITE, rid, data);
|
||||
if (result < 0) {
|
||||
throw new Error("write error");
|
||||
} else {
|
||||
|
@ -56,11 +59,11 @@ export function writeSync(rid: number, p: Uint8Array): number {
|
|||
}
|
||||
}
|
||||
|
||||
export async function write(rid: number, p: Uint8Array): Promise<number> {
|
||||
export async function write(rid: number, data: Uint8Array): Promise<number> {
|
||||
if (OP_WRITE < 0) {
|
||||
OP_WRITE = OPS_CACHE["op_write"];
|
||||
}
|
||||
const result = await sendAsyncMinimal(OP_WRITE, rid, p);
|
||||
const result = await sendAsyncMinimal(OP_WRITE, rid, data);
|
||||
if (result < 0) {
|
||||
throw new Error("write error");
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue