Skip to content

Commit

Permalink
Docs tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Jul 16, 2024
1 parent 347c15b commit 4fb9fc4
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions packages/runtime/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,34 @@ export interface FsFileOptions {
}

/**
* Returns an {@link FsFile} instance for the given `path`.
* Options object for the {@link FsFile.stream | `Switch.FsFile#stream()`} function.
*/
export interface FsFileStreamOptions {
/**
* The size of each chunk to read from the file.
*
* @default 65536
*/
chunkSize: number;
}

/**
* Returns a {@link FsFile | `Switch.FsFile`} instance for the given `path`.
*
* @param path
*/
export function file(path: PathLike, opts?: FsFileOptions) {
return new FsFile(path, opts);
}

/**
* The `Switch.FsFile` class is a special implementation of the
* global {@link File | `File`} class, which interacts with the
* system's physical file system.
*
* It offers a convenient API for working with existing files, and
* also for writing files.
*/
export class FsFile extends File {
constructor(path: PathLike, opts?: FsFileOptions) {
const { bigFile, ...rest } = opts ?? {};
Expand Down Expand Up @@ -189,7 +209,7 @@ export class FsFile extends File {
return JSON.parse(await this.text());
}

stream(opts?: { chunkSize: number }): ReadableStream<Uint8Array> {
stream(opts?: FsFileStreamOptions): ReadableStream<Uint8Array> {
const { name } = this;
const chunkSize = opts?.chunkSize || 65536;
let h: Then<ReturnType<typeof $.fopen>> | null = null;
Expand Down

0 comments on commit 4fb9fc4

Please sign in to comment.