diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2018-10-15 07:29:50 +1100 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-10-14 17:38:23 -0400 |
commit | 10a97679ac80b4304c75d33cbc59c5736d11deb1 (patch) | |
tree | b51b9183ed251f61373069e5c4d35e39603bedb2 /js/files.ts | |
parent | 1840a1971317f5b8fc6e322b3a414b7f8a593c88 (diff) |
Align JSDoc to style guide.
Diffstat (limited to 'js/files.ts')
-rw-r--r-- | js/files.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/js/files.ts b/js/files.ts index c3722a83f..ae36c7a82 100644 --- a/js/files.ts +++ b/js/files.ts @@ -6,6 +6,7 @@ import * as msg from "gen/msg_generated"; import { assert } from "./util"; import { flatbuffers } from "flatbuffers"; +/** The Deno abstraction for reading and writing files. */ export class File implements Reader, Writer, Closer { constructor(readonly rid: number) {} @@ -22,17 +23,30 @@ export class File implements Reader, Writer, Closer { } } +/** An instance of `File` for stdin. */ export const stdin = new File(0); +/** An instance of `File` for stdout. */ export const stdout = new File(1); +/** An instance of `File` for stderr. */ export const stderr = new File(2); // TODO This is just a placeholder - not final API. export type OpenMode = "r" | "w" | "w+" | "x"; +/** A factory function for creating instances of `File` associated with the + * supplied file name. + */ export function create(filename: string): Promise<File> { return open(filename, "x"); } +/** Open a file and return an instance of the `File` object. + * + * import * as deno from "deno"; + * (async () => { + * const file = await deno.open("/foo/bar.txt"); + * })(); + */ export async function open( filename: string, mode: OpenMode = "r" @@ -51,6 +65,10 @@ export async function open( return new File(rid); } +/** Read from a file ID into an array buffer. + * + * Resolves with the `ReadResult` for the operation. + */ export async function read( rid: number, p: ArrayBufferView @@ -67,6 +85,10 @@ export async function read( return { nread: res.nread(), eof: res.eof() }; } +/** Write to the file ID the contents of the array buffer. + * + * Resolves with the number of bytes written. + */ export async function write(rid: number, p: ArrayBufferView): Promise<number> { const builder = new flatbuffers.Builder(); msg.Write.startWrite(builder); @@ -80,6 +102,7 @@ export async function write(rid: number, p: ArrayBufferView): Promise<number> { return res.nbyte(); } +/** Close the file ID. */ export function close(rid: number): void { const builder = new flatbuffers.Builder(); msg.Close.startClose(builder); |