summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/chmod.ts17
-rw-r--r--js/chown.ts18
-rw-r--r--js/copy_file.ts18
-rw-r--r--js/dir.ts19
-rw-r--r--js/dispatch.ts30
-rw-r--r--js/file_info.ts22
-rw-r--r--js/link.ts18
-rw-r--r--js/make_temp_dir.ts36
-rw-r--r--js/mkdir.ts18
-rw-r--r--js/read_dir.ts32
-rw-r--r--js/read_link.ts25
-rw-r--r--js/remove.ts17
-rw-r--r--js/rename.ts18
-rw-r--r--js/stat.ts54
-rw-r--r--js/symlink.ts28
-rw-r--r--js/truncate.ts26
16 files changed, 149 insertions, 247 deletions
diff --git a/js/chmod.ts b/js/chmod.ts
index 2d6a5ed0f..23b3dff25 100644
--- a/js/chmod.ts
+++ b/js/chmod.ts
@@ -1,15 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers";
-
-function req(
- path: string,
- mode: number
-): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
- const builder = flatbuffers.createBuilder();
- const path_ = builder.createString(path);
- const inner = msg.Chmod.createChmod(builder, path_, mode);
- return [builder, msg.Any.Chmod, inner];
-}
+import { sendSync, sendAsync } from "./dispatch_json";
+import * as dispatch from "./dispatch";
/** Changes the permission of a specific file/directory of specified path
* synchronously.
@@ -17,7 +8,7 @@ function req(
* Deno.chmodSync("/path/to/file", 0o666);
*/
export function chmodSync(path: string, mode: number): void {
- sendSync(...req(path, mode));
+ sendSync(dispatch.OP_CHMOD, { path, mode });
}
/** Changes the permission of a specific file/directory of specified path.
@@ -25,5 +16,5 @@ export function chmodSync(path: string, mode: number): void {
* await Deno.chmod("/path/to/file", 0o666);
*/
export async function chmod(path: string, mode: number): Promise<void> {
- await sendAsync(...req(path, mode));
+ await sendAsync(dispatch.OP_CHMOD, { path, mode });
}
diff --git a/js/chown.ts b/js/chown.ts
index 8787033fc..6bfddab98 100644
--- a/js/chown.ts
+++ b/js/chown.ts
@@ -1,16 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers";
-
-function req(
- path: string,
- uid: number,
- gid: number
-): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
- const builder = flatbuffers.createBuilder();
- const path_ = builder.createString(path);
- const inner = msg.Chown.createChown(builder, path_, uid, gid);
- return [builder, msg.Any.Chown, inner];
-}
+import { sendSync, sendAsync } from "./dispatch_json";
+import * as dispatch from "./dispatch";
/**
* Change owner of a regular file or directory synchronously. Unix only at the moment.
@@ -19,7 +9,7 @@ function req(
* @param gid group id of the new owner
*/
export function chownSync(path: string, uid: number, gid: number): void {
- sendSync(...req(path, uid, gid));
+ sendSync(dispatch.OP_CHOWN, { path, uid, gid });
}
/**
@@ -33,5 +23,5 @@ export async function chown(
uid: number,
gid: number
): Promise<void> {
- await sendAsync(...req(path, uid, gid));
+ await sendAsync(dispatch.OP_CHOWN, { path, uid, gid });
}
diff --git a/js/copy_file.ts b/js/copy_file.ts
index 4c62ed1b0..b299a52bc 100644
--- a/js/copy_file.ts
+++ b/js/copy_file.ts
@@ -1,16 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers";
-
-function req(
- from: string,
- to: string
-): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
- const builder = flatbuffers.createBuilder();
- const from_ = builder.createString(from);
- const to_ = builder.createString(to);
- const inner = msg.CopyFile.createCopyFile(builder, from_, to_);
- return [builder, msg.Any.CopyFile, inner];
-}
+import { sendSync, sendAsync } from "./dispatch_json";
+import * as dispatch from "./dispatch";
/** Copies the contents of a file to another by name synchronously.
* Creates a new file if target does not exists, and if target exists,
@@ -22,7 +12,7 @@ function req(
* Deno.copyFileSync("from.txt", "to.txt");
*/
export function copyFileSync(from: string, to: string): void {
- sendSync(...req(from, to));
+ sendSync(dispatch.OP_COPY_FILE, { from, to });
}
/** Copies the contents of a file to another by name.
@@ -36,5 +26,5 @@ export function copyFileSync(from: string, to: string): void {
* await Deno.copyFile("from.txt", "to.txt");
*/
export async function copyFile(from: string, to: string): Promise<void> {
- await sendAsync(...req(from, to));
+ await sendAsync(dispatch.OP_COPY_FILE, { from, to });
}
diff --git a/js/dir.ts b/js/dir.ts
index 824084f4d..f2cf91c21 100644
--- a/js/dir.ts
+++ b/js/dir.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { assert } from "./util";
-import { sendSync, flatbuffers, msg } from "./dispatch_flatbuffers";
+import { sendSync } from "./dispatch_json";
+import * as dispatch from "./dispatch";
/**
* `cwd()` Return a string representing the current working directory.
@@ -10,15 +10,7 @@ import { sendSync, flatbuffers, msg } from "./dispatch_flatbuffers";
* throws `NotFound` exception if directory not available
*/
export function cwd(): string {
- const builder = flatbuffers.createBuilder();
- msg.Cwd.startCwd(builder);
- const inner = msg.Cwd.endCwd(builder);
- const baseRes = sendSync(builder, msg.Any.Cwd, inner);
- assert(baseRes != null);
- assert(msg.Any.CwdRes === baseRes!.innerType());
- const res = new msg.CwdRes();
- assert(baseRes!.inner(res) != null);
- return res.cwd()!;
+ return sendSync(dispatch.OP_CWD);
}
/**
@@ -26,8 +18,5 @@ export function cwd(): string {
* throws `NotFound` exception if directory not available
*/
export function chdir(directory: string): void {
- const builder = flatbuffers.createBuilder();
- const directory_ = builder.createString(directory);
- const inner = msg.Chdir.createChdir(builder, directory_);
- sendSync(builder, msg.Any.Chdir, inner);
+ sendSync(dispatch.OP_CHDIR, { directory });
}
diff --git a/js/dispatch.ts b/js/dispatch.ts
index 6c7551441..2416c19e2 100644
--- a/js/dispatch.ts
+++ b/js/dispatch.ts
@@ -4,7 +4,7 @@ import * as flatbuffers from "./dispatch_flatbuffers";
import * as json from "./dispatch_json";
// These consts are shared with Rust. Update with care.
-export const OP_FLATBUFFER = 44;
+export const OP_FLATBUFFER = 100;
export const OP_READ = 1;
export const OP_WRITE = 2;
export const OP_EXIT = 3;
@@ -46,6 +46,21 @@ export const OP_WORKER_GET_MESSAGE = 38;
export const OP_RUN = 39;
export const OP_RUN_STATUS = 40;
export const OP_KILL = 41;
+export const OP_CHDIR = 42;
+export const OP_MKDIR = 43;
+export const OP_CHMOD = 44;
+export const OP_CHOWN = 45;
+export const OP_REMOVE = 46;
+export const OP_COPY_FILE = 47;
+export const OP_STAT = 48;
+export const OP_READ_DIR = 49;
+export const OP_RENAME = 50;
+export const OP_LINK = 51;
+export const OP_SYMLINK = 52;
+export const OP_READ_LINK = 53;
+export const OP_TRUNCATE = 54;
+export const OP_MAKE_TEMP_DIR = 55;
+export const OP_CWD = 56;
export function asyncMsgFromRust(opId: number, ui8: Uint8Array): void {
switch (opId) {
@@ -73,6 +88,19 @@ export function asyncMsgFromRust(opId: number, ui8: Uint8Array): void {
case OP_HOST_GET_MESSAGE:
case OP_WORKER_GET_MESSAGE:
case OP_RUN_STATUS:
+ case OP_MKDIR:
+ case OP_CHMOD:
+ case OP_CHOWN:
+ case OP_REMOVE:
+ case OP_COPY_FILE:
+ case OP_STAT:
+ case OP_READ_DIR:
+ case OP_RENAME:
+ case OP_LINK:
+ case OP_SYMLINK:
+ case OP_READ_LINK:
+ case OP_TRUNCATE:
+ case OP_MAKE_TEMP_DIR:
json.asyncMsgFromRust(opId, ui8);
break;
default:
diff --git a/js/file_info.ts b/js/file_info.ts
index f2e5a88ae..c124e06bf 100644
--- a/js/file_info.ts
+++ b/js/file_info.ts
@@ -1,5 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as msg from "gen/cli/msg_generated";
+import { StatResponse } from "./stat";
/** A FileInfo describes a file and is returned by `stat`, `lstat`,
* `statSync`, `lstatSync`.
@@ -58,17 +58,17 @@ export class FileInfoImpl implements FileInfo {
name: string | null;
/* @internal */
- constructor(private _inner: msg.StatRes) {
- const modified = this._inner.modified().toFloat64();
- const accessed = this._inner.accessed().toFloat64();
- const created = this._inner.created().toFloat64();
- const hasMode = this._inner.hasMode();
- const mode = this._inner.mode(); // negative for invalid mode (Windows)
- const name = this._inner.name();
+ constructor(private _res: StatResponse) {
+ const modified = this._res.modified;
+ const accessed = this._res.accessed;
+ const created = this._res.created;
+ const hasMode = this._res.hasMode;
+ const mode = this._res.mode; // negative for invalid mode (Windows)
+ const name = this._res.name;
- this._isFile = this._inner.isFile();
- this._isSymlink = this._inner.isSymlink();
- this.len = this._inner.len().toFloat64();
+ this._isFile = this._res.isFile;
+ this._isSymlink = this._res.isSymlink;
+ this.len = this._res.len;
this.modified = modified ? modified : null;
this.accessed = accessed ? accessed : null;
this.created = created ? created : null;
diff --git a/js/link.ts b/js/link.ts
index 0d849d289..f6c6530b2 100644
--- a/js/link.ts
+++ b/js/link.ts
@@ -1,23 +1,13 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers";
-
-function req(
- oldname: string,
- newname: string
-): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
- const builder = flatbuffers.createBuilder();
- const oldname_ = builder.createString(oldname);
- const newname_ = builder.createString(newname);
- const inner = msg.Link.createLink(builder, oldname_, newname_);
- return [builder, msg.Any.Link, inner];
-}
+import { sendSync, sendAsync } from "./dispatch_json";
+import * as dispatch from "./dispatch";
/** Synchronously creates `newname` as a hard link to `oldname`.
*
* Deno.linkSync("old/name", "new/name");
*/
export function linkSync(oldname: string, newname: string): void {
- sendSync(...req(oldname, newname));
+ sendSync(dispatch.OP_LINK, { oldname, newname });
}
/** Creates `newname` as a hard link to `oldname`.
@@ -25,5 +15,5 @@ export function linkSync(oldname: string, newname: string): void {
* await Deno.link("old/name", "new/name");
*/
export async function link(oldname: string, newname: string): Promise<void> {
- await sendAsync(...req(oldname, newname));
+ await sendAsync(dispatch.OP_LINK, { oldname, newname });
}
diff --git a/js/make_temp_dir.ts b/js/make_temp_dir.ts
index f83f7fb60..5e0a28205 100644
--- a/js/make_temp_dir.ts
+++ b/js/make_temp_dir.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers";
-import { assert } from "./util";
+import { sendSync, sendAsync } from "./dispatch_json";
+import * as dispatch from "./dispatch";
export interface MakeTempDirOptions {
dir?: string;
@@ -8,41 +8,13 @@ export interface MakeTempDirOptions {
suffix?: string;
}
-function req({
- dir,
- prefix,
- suffix
-}: MakeTempDirOptions): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
- const builder = flatbuffers.createBuilder();
- const fbDir = dir == null ? 0 : builder.createString(dir);
- const fbPrefix = prefix == null ? 0 : builder.createString(prefix);
- const fbSuffix = suffix == null ? 0 : builder.createString(suffix);
- const inner = msg.MakeTempDir.createMakeTempDir(
- builder,
- fbDir,
- fbPrefix,
- fbSuffix
- );
- return [builder, msg.Any.MakeTempDir, inner];
-}
-
-function res(baseRes: null | msg.Base): string {
- assert(baseRes != null);
- assert(msg.Any.MakeTempDirRes === baseRes!.innerType());
- const res = new msg.MakeTempDirRes();
- assert(baseRes!.inner(res) != null);
- const path = res.path();
- assert(path != null);
- return path!;
-}
-
/** makeTempDirSync is the synchronous version of `makeTempDir`.
*
* const tempDirName0 = Deno.makeTempDirSync();
* const tempDirName1 = Deno.makeTempDirSync({ prefix: 'my_temp' });
*/
export function makeTempDirSync(options: MakeTempDirOptions = {}): string {
- return res(sendSync(...req(options)));
+ return sendSync(dispatch.OP_MAKE_TEMP_DIR, options);
}
/** makeTempDir creates a new temporary directory in the directory `dir`, its
@@ -59,5 +31,5 @@ export function makeTempDirSync(options: MakeTempDirOptions = {}): string {
export async function makeTempDir(
options: MakeTempDirOptions = {}
): Promise<string> {
- return res(await sendAsync(...req(options)));
+ return await sendAsync(dispatch.OP_MAKE_TEMP_DIR, options);
}
diff --git a/js/mkdir.ts b/js/mkdir.ts
index 417c754a9..54f99224b 100644
--- a/js/mkdir.ts
+++ b/js/mkdir.ts
@@ -1,16 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers";
-
-function req(
- path: string,
- recursive: boolean,
- mode: number
-): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
- const builder = flatbuffers.createBuilder();
- const path_ = builder.createString(path);
- const inner = msg.Mkdir.createMkdir(builder, path_, recursive, mode);
- return [builder, msg.Any.Mkdir, inner];
-}
+import { sendSync, sendAsync } from "./dispatch_json";
+import * as dispatch from "./dispatch";
/** Creates a new directory with the specified path synchronously.
* If `recursive` is set to true, nested directories will be created (also known
@@ -22,7 +12,7 @@ function req(
* Deno.mkdirSync("nested/directories", true);
*/
export function mkdirSync(path: string, recursive = false, mode = 0o777): void {
- sendSync(...req(path, recursive, mode));
+ sendSync(dispatch.OP_MKDIR, { path, recursive, mode });
}
/** Creates a new directory with the specified path.
@@ -39,5 +29,5 @@ export async function mkdir(
recursive = false,
mode = 0o777
): Promise<void> {
- await sendAsync(...req(path, recursive, mode));
+ await sendAsync(dispatch.OP_MKDIR, { path, recursive, mode });
}
diff --git a/js/read_dir.ts b/js/read_dir.ts
index 13c620916..27d011a08 100644
--- a/js/read_dir.ts
+++ b/js/read_dir.ts
@@ -1,25 +1,19 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers";
+import { sendSync, sendAsync } from "./dispatch_json";
+import * as dispatch from "./dispatch";
import { FileInfo, FileInfoImpl } from "./file_info";
-import { assert } from "./util";
+import { StatResponse } from "./stat";
-function req(path: string): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
- const builder = flatbuffers.createBuilder();
- const path_ = builder.createString(path);
- const inner = msg.ReadDir.createReadDir(builder, path_);
- return [builder, msg.Any.ReadDir, inner];
+interface ReadDirResponse {
+ entries: StatResponse[];
}
-function res(baseRes: null | msg.Base): FileInfo[] {
- assert(baseRes != null);
- assert(msg.Any.ReadDirRes === baseRes!.innerType());
- const res = new msg.ReadDirRes();
- assert(baseRes!.inner(res) != null);
- const fileInfos: FileInfo[] = [];
- for (let i = 0; i < res.entriesLength(); i++) {
- fileInfos.push(new FileInfoImpl(res.entries(i)!));
- }
- return fileInfos;
+function res(response: ReadDirResponse): FileInfo[] {
+ return response.entries.map(
+ (statRes: StatResponse): FileInfo => {
+ return new FileInfoImpl(statRes);
+ }
+ );
}
/** Reads the directory given by path and returns a list of file info
@@ -28,7 +22,7 @@ function res(baseRes: null | msg.Base): FileInfo[] {
* const files = Deno.readDirSync("/");
*/
export function readDirSync(path: string): FileInfo[] {
- return res(sendSync(...req(path)));
+ return res(sendSync(dispatch.OP_READ_DIR, { path }));
}
/** Reads the directory given by path and returns a list of file info.
@@ -36,5 +30,5 @@ export function readDirSync(path: string): FileInfo[] {
* const files = await Deno.readDir("/");
*/
export async function readDir(path: string): Promise<FileInfo[]> {
- return res(await sendAsync(...req(path)));
+ return res(await sendAsync(dispatch.OP_READ_DIR, { path }));
}
diff --git a/js/read_link.ts b/js/read_link.ts
index 8cac67dd1..fae1e64b6 100644
--- a/js/read_link.ts
+++ b/js/read_link.ts
@@ -1,30 +1,13 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { assert } from "./util";
-import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers";
-
-function req(name: string): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
- const builder = flatbuffers.createBuilder();
- const name_ = builder.createString(name);
- const inner = msg.Readlink.createReadlink(builder, name_);
- return [builder, msg.Any.Readlink, inner];
-}
-
-function res(baseRes: null | msg.Base): string {
- assert(baseRes !== null);
- assert(msg.Any.ReadlinkRes === baseRes!.innerType());
- const res = new msg.ReadlinkRes();
- assert(baseRes!.inner(res) !== null);
- const path = res.path();
- assert(path !== null);
- return path!;
-}
+import { sendSync, sendAsync } from "./dispatch_json";
+import * as dispatch from "./dispatch";
/** Returns the destination of the named symbolic link synchronously.
*
* const targetPath = Deno.readlinkSync("symlink/path");
*/
export function readlinkSync(name: string): string {
- return res(sendSync(...req(name)));
+ return sendSync(dispatch.OP_READ_LINK, { name });
}
/** Returns the destination of the named symbolic link.
@@ -32,5 +15,5 @@ export function readlinkSync(name: string): string {
* const targetPath = await Deno.readlink("symlink/path");
*/
export async function readlink(name: string): Promise<string> {
- return res(await sendAsync(...req(name)));
+ return await sendAsync(dispatch.OP_READ_LINK, { name });
}
diff --git a/js/remove.ts b/js/remove.ts
index 95294e6cf..f2a94f395 100644
--- a/js/remove.ts
+++ b/js/remove.ts
@@ -1,20 +1,11 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers";
+import { sendSync, sendAsync } from "./dispatch_json";
+import * as dispatch from "./dispatch";
export interface RemoveOption {
recursive?: boolean;
}
-function req(
- path: string,
- options: RemoveOption
-): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
- const builder = flatbuffers.createBuilder();
- const path_ = builder.createString(path);
- const inner = msg.Remove.createRemove(builder, path_, !!options.recursive);
- return [builder, msg.Any.Remove, inner];
-}
-
/** Removes the named file or directory synchronously. Would throw
* error if permission denied, not found, or directory not empty if `recursive`
* set to false.
@@ -23,7 +14,7 @@ function req(
* Deno.removeSync("/path/to/dir/or/file", {recursive: false});
*/
export function removeSync(path: string, options: RemoveOption = {}): void {
- sendSync(...req(path, options));
+ sendSync(dispatch.OP_REMOVE, { path, recursive: !!options.recursive });
}
/** Removes the named file or directory. Would throw error if
@@ -37,5 +28,5 @@ export async function remove(
path: string,
options: RemoveOption = {}
): Promise<void> {
- await sendAsync(...req(path, options));
+ await sendAsync(dispatch.OP_REMOVE, { path, recursive: !!options.recursive });
}
diff --git a/js/rename.ts b/js/rename.ts
index 31f480d0e..80794747d 100644
--- a/js/rename.ts
+++ b/js/rename.ts
@@ -1,16 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers";
-
-function req(
- oldpath: string,
- newpath: string
-): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
- const builder = flatbuffers.createBuilder();
- const oldpath_ = builder.createString(oldpath);
- const newpath_ = builder.createString(newpath);
- const inner = msg.Rename.createRename(builder, oldpath_, newpath_);
- return [builder, msg.Any.Rename, inner];
-}
+import { sendSync, sendAsync } from "./dispatch_json";
+import * as dispatch from "./dispatch";
/** Synchronously renames (moves) `oldpath` to `newpath`. If `newpath` already
* exists and is not a directory, `renameSync()` replaces it. OS-specific
@@ -20,7 +10,7 @@ function req(
* Deno.renameSync("old/path", "new/path");
*/
export function renameSync(oldpath: string, newpath: string): void {
- sendSync(...req(oldpath, newpath));
+ sendSync(dispatch.OP_RENAME, { oldpath, newpath });
}
/** Renames (moves) `oldpath` to `newpath`. If `newpath` already exists and is
@@ -30,5 +20,5 @@ export function renameSync(oldpath: string, newpath: string): void {
* await Deno.rename("old/path", "new/path");
*/
export async function rename(oldpath: string, newpath: string): Promise<void> {
- await sendAsync(...req(oldpath, newpath));
+ await sendAsync(dispatch.OP_RENAME, { oldpath, newpath });
}
diff --git a/js/stat.ts b/js/stat.ts
index 1fcce82af..1cc8d070a 100644
--- a/js/stat.ts
+++ b/js/stat.ts
@@ -1,24 +1,18 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers";
-import { assert } from "./util";
+import { sendSync, sendAsync } from "./dispatch_json";
+import * as dispatch from "./dispatch";
import { FileInfo, FileInfoImpl } from "./file_info";
-function req(
- filename: string,
- lstat: boolean
-): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
- const builder = flatbuffers.createBuilder();
- const filename_ = builder.createString(filename);
- const inner = msg.Stat.createStat(builder, filename_, lstat);
- return [builder, msg.Any.Stat, inner];
-}
-
-function res(baseRes: null | msg.Base): FileInfo {
- assert(baseRes != null);
- assert(msg.Any.StatRes === baseRes!.innerType());
- const res = new msg.StatRes();
- assert(baseRes!.inner(res) != null);
- return new FileInfoImpl(res);
+export interface StatResponse {
+ isFile: boolean;
+ isSymlink: boolean;
+ len: number;
+ modified: number;
+ accessed: number;
+ created: number;
+ mode: number;
+ hasMode: boolean; // false on windows
+ name: string | null;
}
/** Queries the file system for information on the path provided. If the given
@@ -28,7 +22,11 @@ function res(baseRes: null | msg.Base): FileInfo {
* assert(fileInfo.isFile());
*/
export async function lstat(filename: string): Promise<FileInfo> {
- return res(await sendAsync(...req(filename, true)));
+ const res = (await sendAsync(dispatch.OP_STAT, {
+ filename,
+ lstat: true
+ })) as StatResponse;
+ return new FileInfoImpl(res);
}
/** Queries the file system for information on the path provided synchronously.
@@ -39,7 +37,11 @@ export async function lstat(filename: string): Promise<FileInfo> {
* assert(fileInfo.isFile());
*/
export function lstatSync(filename: string): FileInfo {
- return res(sendSync(...req(filename, true)));
+ const res = sendSync(dispatch.OP_STAT, {
+ filename,
+ lstat: true
+ }) as StatResponse;
+ return new FileInfoImpl(res);
}
/** Queries the file system for information on the path provided. `stat` Will
@@ -49,7 +51,11 @@ export function lstatSync(filename: string): FileInfo {
* assert(fileInfo.isFile());
*/
export async function stat(filename: string): Promise<FileInfo> {
- return res(await sendAsync(...req(filename, false)));
+ const res = (await sendAsync(dispatch.OP_STAT, {
+ filename,
+ lstat: false
+ })) as StatResponse;
+ return new FileInfoImpl(res);
}
/** Queries the file system for information on the path provided synchronously.
@@ -59,5 +65,9 @@ export async function stat(filename: string): Promise<FileInfo> {
* assert(fileInfo.isFile());
*/
export function statSync(filename: string): FileInfo {
- return res(sendSync(...req(filename, false)));
+ const res = sendSync(dispatch.OP_STAT, {
+ filename,
+ lstat: false
+ }) as StatResponse;
+ return new FileInfoImpl(res);
}
diff --git a/js/symlink.ts b/js/symlink.ts
index 40551e9f8..6fd2e90a5 100644
--- a/js/symlink.ts
+++ b/js/symlink.ts
@@ -1,23 +1,9 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers";
+import { sendSync, sendAsync } from "./dispatch_json";
+import * as dispatch from "./dispatch";
import * as util from "./util";
import { platform } from "./build";
-function req(
- oldname: string,
- newname: string,
- type?: string
-): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
- if (platform.os === "win" && type) {
- return util.notImplemented();
- }
- const builder = flatbuffers.createBuilder();
- const oldname_ = builder.createString(oldname);
- const newname_ = builder.createString(newname);
- const inner = msg.Symlink.createSymlink(builder, oldname_, newname_);
- return [builder, msg.Any.Symlink, inner];
-}
-
/** Synchronously creates `newname` as a symbolic link to `oldname`. The type
* argument can be set to `dir` or `file` and is only available on Windows
* (ignored on other platforms).
@@ -29,7 +15,10 @@ export function symlinkSync(
newname: string,
type?: string
): void {
- sendSync(...req(oldname, newname, type));
+ if (platform.os === "win" && type) {
+ return util.notImplemented();
+ }
+ sendSync(dispatch.OP_SYMLINK, { oldname, newname });
}
/** Creates `newname` as a symbolic link to `oldname`. The type argument can be
@@ -43,5 +32,8 @@ export async function symlink(
newname: string,
type?: string
): Promise<void> {
- await sendAsync(...req(oldname, newname, type));
+ if (platform.os === "win" && type) {
+ return util.notImplemented();
+ }
+ await sendAsync(dispatch.OP_SYMLINK, { oldname, newname });
}
diff --git a/js/truncate.ts b/js/truncate.ts
index 259c57da5..c6e5b3ad0 100644
--- a/js/truncate.ts
+++ b/js/truncate.ts
@@ -1,15 +1,17 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers";
+import { sendSync, sendAsync } from "./dispatch_json";
+import * as dispatch from "./dispatch";
-function req(
- name: string,
- len?: number
-): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
- const builder = flatbuffers.createBuilder();
- const name_ = builder.createString(name);
- len = len && len > 0 ? Math.floor(len) : 0;
- const inner = msg.Truncate.createTruncate(builder, name_, len);
- return [builder, msg.Any.Truncate, inner];
+function coerceLen(len?: number): number {
+ if (!len) {
+ return 0;
+ }
+
+ if (len < 0) {
+ return 0;
+ }
+
+ return len;
}
/** Truncates or extends the specified file synchronously, updating the size of
@@ -18,7 +20,7 @@ function req(
* Deno.truncateSync("hello.txt", 10);
*/
export function truncateSync(name: string, len?: number): void {
- sendSync(...req(name, len));
+ sendSync(dispatch.OP_TRUNCATE, { name, len: coerceLen(len) });
}
/**
@@ -28,5 +30,5 @@ export function truncateSync(name: string, len?: number): void {
* await Deno.truncate("hello.txt", 10);
*/
export async function truncate(name: string, len?: number): Promise<void> {
- await sendAsync(...req(name, len));
+ await sendAsync(dispatch.OP_TRUNCATE, { name, len: coerceLen(len) });
}