summaryrefslogtreecommitdiff
path: root/js/make_temp_dir.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2019-08-26 16:18:42 +0200
committerRyan Dahl <ry@tinyclouds.org>2019-08-26 10:18:42 -0400
commita6f6209f5277f2737bc67efad5c91ab168aff6b5 (patch)
tree88e8449e61e09cf5037def8d723ec43654d31b06 /js/make_temp_dir.ts
parent520f9631e09aa720fd8c03513ee8ea967f5ed4b2 (diff)
port fs ops to JSON (#2812)
Diffstat (limited to 'js/make_temp_dir.ts')
-rw-r--r--js/make_temp_dir.ts36
1 files changed, 4 insertions, 32 deletions
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);
}