summaryrefslogtreecommitdiff
path: root/js/files.ts
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2019-03-10 04:30:38 +1100
committerRyan Dahl <ry@tinyclouds.org>2019-03-09 12:30:38 -0500
commit034e2cc02829c9244b32232074c7a48af827a2fb (patch)
treebade01606a1ee076c1f753ce99c97ddb1e4edf30 /js/files.ts
parent8c7a12d1b258f0ef5ab27f49c424331d43e8d97f (diff)
Migrate from tslint to eslint for linting (#1905)
Diffstat (limited to 'js/files.ts')
-rw-r--r--js/files.ts125
1 files changed, 63 insertions, 62 deletions
diff --git a/js/files.ts b/js/files.ts
index a77f788df..9ea378735 100644
--- a/js/files.ts
+++ b/js/files.ts
@@ -5,68 +5,6 @@ import * as msg from "gen/msg_generated";
import { assert } from "./util";
import * as flatbuffers from "./flatbuffers";
-/** The Deno abstraction for reading and writing files. */
-export class File implements Reader, Writer, Seeker, Closer {
- constructor(readonly rid: number) {}
-
- write(p: Uint8Array): Promise<number> {
- return write(this.rid, p);
- }
-
- read(p: Uint8Array): Promise<ReadResult> {
- return read(this.rid, p);
- }
-
- seek(offset: number, whence: SeekMode): Promise<void> {
- return seek(this.rid, offset, whence);
- }
-
- close(): void {
- close(this.rid);
- }
-}
-
-/** 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);
-
-export type OpenMode =
- /** Read-only. Default. Starts at beginning of file. */
- | "r"
- /** Read-write. Start at beginning of file. */
- | "r+"
- /** Write-only. Opens and truncates existing file or creates new one for
- * writing only.
- */
- | "w"
- /** Read-write. Opens and truncates existing file or creates new one for
- * writing and reading.
- */
- | "w+"
- /** Write-only. Opens existing file or creates new one. Each write appends
- * content to the end of file.
- */
- | "a"
- /** Read-write. Behaves like "a" and allows to read from file. */
- | "a+"
- /** Write-only. Exclusive create - creates new file only if one doesn't exist
- * already.
- */
- | "x"
- /** Read-write. Behaves like `x` and allows to read from file. */
- | "x+";
-
-/** A factory function for creating instances of `File` associated with the
- * supplied file name.
- * @internal
- */
-export function create(filename: string): Promise<File> {
- return open(filename, "w+");
-}
-
/** Open a file and return an instance of the `File` object.
*
* (async () => {
@@ -90,6 +28,7 @@ export async function open(
const res = new msg.OpenRes();
assert(baseRes!.inner(res) != null);
const rid = res.rid();
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
return new File(rid);
}
@@ -152,3 +91,65 @@ export function close(rid: number): void {
const inner = msg.Close.endClose(builder);
dispatch.sendSync(builder, msg.Any.Close, inner);
}
+
+/** The Deno abstraction for reading and writing files. */
+export class File implements Reader, Writer, Seeker, Closer {
+ constructor(readonly rid: number) {}
+
+ write(p: Uint8Array): Promise<number> {
+ return write(this.rid, p);
+ }
+
+ read(p: Uint8Array): Promise<ReadResult> {
+ return read(this.rid, p);
+ }
+
+ seek(offset: number, whence: SeekMode): Promise<void> {
+ return seek(this.rid, offset, whence);
+ }
+
+ close(): void {
+ close(this.rid);
+ }
+}
+
+/** 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);
+
+export type OpenMode =
+ /** Read-only. Default. Starts at beginning of file. */
+ | "r"
+ /** Read-write. Start at beginning of file. */
+ | "r+"
+ /** Write-only. Opens and truncates existing file or creates new one for
+ * writing only.
+ */
+ | "w"
+ /** Read-write. Opens and truncates existing file or creates new one for
+ * writing and reading.
+ */
+ | "w+"
+ /** Write-only. Opens existing file or creates new one. Each write appends
+ * content to the end of file.
+ */
+ | "a"
+ /** Read-write. Behaves like "a" and allows to read from file. */
+ | "a+"
+ /** Write-only. Exclusive create - creates new file only if one doesn't exist
+ * already.
+ */
+ | "x"
+ /** Read-write. Behaves like `x` and allows to read from file. */
+ | "x+";
+
+/** A factory function for creating instances of `File` associated with the
+ * supplied file name.
+ * @internal
+ */
+export function create(filename: string): Promise<File> {
+ return open(filename, "w+");
+}