[oden] Native IO module
This commit is contained in:
parent
f7ed78ce3b
commit
4959adc7e6
3 changed files with 20 additions and 1 deletions
11
src/io.ts
Normal file
11
src/io.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import * as core from "io-core";
|
||||
|
||||
/**
|
||||
* Load the specified file into memory.
|
||||
*
|
||||
* @param path The path of the file to load.
|
||||
* @returns The contents of the file.
|
||||
*/
|
||||
export function load(path: string): Promise<ArrayBuffer> {
|
||||
return core.load(path);
|
||||
}
|
||||
|
|
@ -71,7 +71,12 @@ impl IoImpl {
|
|||
self.thread_pool.execute(Box::new(move || {
|
||||
// TODO: Actually read the path.
|
||||
let path = path;
|
||||
promise.resolve(move |ctx: &ContextRef| ctx.new_string(&path));
|
||||
|
||||
let result = std::fs::read(path);
|
||||
promise.resolve(move |ctx: &ContextRef| match result {
|
||||
Ok(v) => ctx.new_array_buffer(v),
|
||||
Err(err) => Err(err.into()),
|
||||
});
|
||||
}));
|
||||
|
||||
Ok(value)
|
||||
|
|
|
|||
3
types/io-core.d.ts
vendored
Normal file
3
types/io-core.d.ts
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// These are the functions exposed by the native IO module.
|
||||
//
|
||||
export function load(path: string): Promise<ArrayBuffer>;
|
||||
Loading…
Add table
Add a link
Reference in a new issue