mirror of
https://github.com/denoland/deno.git
synced 2024-10-31 09:14:20 -04:00
c9614d86c1
Fixes some sed errors introduced in c43cfe. Unfortunately moving libdeno required splitting build.rs into two parts, one for cli and one for core. I've also removed the arm64 build - it's complicating things at this re-org and we're not even testing it. I need to swing back to it and get tools/test.py running for it.
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
|
import * as msg from "gen/cli/msg_generated";
|
|
import * as flatbuffers from "./flatbuffers";
|
|
import * as dispatch from "./dispatch";
|
|
import { FileInfo, FileInfoImpl } from "./file_info";
|
|
import { assert } from "./util";
|
|
|
|
function req(path: string): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
|
|
const builder = flatbuffers.createBuilder();
|
|
const path_ = builder.createString(path);
|
|
msg.ReadDir.startReadDir(builder);
|
|
msg.ReadDir.addPath(builder, path_);
|
|
const inner = msg.ReadDir.endReadDir(builder);
|
|
return [builder, msg.Any.ReadDir, inner];
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
/** Reads the directory given by path and returns a list of file info
|
|
* synchronously.
|
|
*
|
|
* const files = Deno.readDirSync("/");
|
|
*/
|
|
export function readDirSync(path: string): FileInfo[] {
|
|
return res(dispatch.sendSync(...req(path)));
|
|
}
|
|
|
|
/** Reads the directory given by path and returns a list of file info.
|
|
*
|
|
* const files = await Deno.readDir("/");
|
|
*/
|
|
export async function readDir(path: string): Promise<FileInfo[]> {
|
|
return res(await dispatch.sendAsync(...req(path)));
|
|
}
|