summaryrefslogtreecommitdiff
path: root/js/utime.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/utime.ts')
-rw-r--r--js/utime.ts37
1 files changed, 16 insertions, 21 deletions
diff --git a/js/utime.ts b/js/utime.ts
index 89914b4ca..c71710458 100644
--- a/js/utime.ts
+++ b/js/utime.ts
@@ -1,24 +1,9 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync, msg, flatbuffers } from "./dispatch_flatbuffers";
-import * as util from "./util";
+import { sendSync, sendAsync } from "./dispatch_json";
+import { OP_UTIME } from "./dispatch";
-function req(
- filename: string,
- atime: number | Date,
- mtime: number | Date
-): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
- const atimeSec = atime instanceof Date ? Math.floor(+atime / 1000) : atime;
- const mtimeSec = mtime instanceof Date ? Math.floor(+mtime / 1000) : mtime;
-
- const builder = flatbuffers.createBuilder();
- const filename_ = builder.createString(filename);
- const atimeParts = util.splitNumberToParts(atimeSec);
- const atimeMS_ = builder.createLong(atimeParts[0], atimeParts[1]);
- const mtimeParts = util.splitNumberToParts(mtimeSec);
- const mtimeMS_ = builder.createLong(mtimeParts[0], mtimeParts[1]);
-
- const inner = msg.Utime.createUtime(builder, filename_, atimeMS_, mtimeMS_);
- return [builder, msg.Any.Utime, inner];
+function toSecondsFromEpoch(v: number | Date): number {
+ return v instanceof Date ? v.valueOf() / 1000 : v;
}
/** Synchronously changes the access and modification times of a file system
@@ -32,7 +17,12 @@ export function utimeSync(
atime: number | Date,
mtime: number | Date
): void {
- sendSync(...req(filename, atime, mtime));
+ sendSync(OP_UTIME, {
+ filename,
+ // TODO(ry) split atime, mtime into [seconds, nanoseconds] tuple
+ atime: toSecondsFromEpoch(atime),
+ mtime: toSecondsFromEpoch(mtime)
+ });
}
/** Changes the access and modification times of a file system object
@@ -46,5 +36,10 @@ export async function utime(
atime: number | Date,
mtime: number | Date
): Promise<void> {
- await sendAsync(...req(filename, atime, mtime));
+ await sendAsync(OP_UTIME, {
+ filename,
+ // TODO(ry) split atime, mtime into [seconds, nanoseconds] tuple
+ atime: toSecondsFromEpoch(atime),
+ mtime: toSecondsFromEpoch(mtime)
+ });
}