diff options
Diffstat (limited to 'js/truncate.ts')
-rw-r--r-- | js/truncate.ts | 26 |
1 files changed, 14 insertions, 12 deletions
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) }); } |