clean up code in cli/js (#6611)

This commit is contained in:
Stanislav 2020-07-07 04:45:39 +03:00 committed by GitHub
parent ab4c574f52
commit 158ae0bfe9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
89 changed files with 395 additions and 354 deletions

View file

@ -3,50 +3,48 @@
import { sendAsyncMinimal, sendSyncMinimal } from "./dispatch_minimal.ts";
export function readSync(rid: number, buffer: Uint8Array): number | null {
if (buffer.length == 0) {
if (buffer.length === 0) {
return 0;
}
const nread = sendSyncMinimal("op_read", rid, buffer);
if (nread < 0) {
throw new Error("read error");
} else if (nread == 0) {
return null;
} else {
return nread;
}
return nread === 0 ? null : nread;
}
export async function read(
rid: number,
buffer: Uint8Array
): Promise<number | null> {
if (buffer.length == 0) {
if (buffer.length === 0) {
return 0;
}
const nread = await sendAsyncMinimal("op_read", rid, buffer);
if (nread < 0) {
throw new Error("read error");
} else if (nread == 0) {
return null;
} else {
return nread;
}
return nread === 0 ? null : nread;
}
export function writeSync(rid: number, data: Uint8Array): number {
const result = sendSyncMinimal("op_write", rid, data);
if (result < 0) {
throw new Error("write error");
} else {
return result;
}
return result;
}
export async function write(rid: number, data: Uint8Array): Promise<number> {
const result = await sendAsyncMinimal("op_write", rid, data);
if (result < 0) {
throw new Error("write error");
} else {
return result;
}
return result;
}