1use wasm_bindgen::prelude::*;
2
3pub fn read_file_sync(path: &str) -> Vec<u8> {
4 let fs = node_require("fs");
5 fs.readFileSync(path)
6}
7
8pub fn write_file_sync(path: &str, data: &[u8]) {
9 let fs = node_require("fs");
10 fs.writeFileSync(path, data);
11}
12
13pub fn append_file_sync(path: &str, data: &[u8]) {
14 let fs = node_require("fs");
15 fs.appendFileSync(path, data);
16}
17
18pub fn copy_file_sync(path_src: &str, path_dest: &str) {
19 let fs = node_require("fs");
20 fs.copyFileSync(path_src, path_dest);
21}
22
23pub fn rename_sync(path_src: &str, path_dest: &str) {
24 let fs = node_require("fs");
25 fs.renameSync(path_src, path_dest);
26}
27
28pub fn unlink_sync(path: &str) {
29 let fs = node_require("fs");
30 fs.unlinkSync(path);
31}
32
33#[wasm_bindgen]
34extern "C" {
35 #[wasm_bindgen(js_name = require)]
36 fn node_require(s: &str) -> NodeFs;
37
38 #[derive(Clone, Debug)]
39 type NodeFs;
40
41 #[wasm_bindgen(method, js_name = readFileSync, structural)]
42 fn readFileSync(me: &NodeFs, path: &str) -> Vec<u8>;
43
44 #[wasm_bindgen(method, js_name = writeFileSync, structural)]
45 fn writeFileSync(me: &NodeFs, path: &str, data: &[u8]);
46
47 #[wasm_bindgen(method, js_name = appendFileSync, structural)]
48 fn appendFileSync(me: &NodeFs, path: &str, data: &[u8]);
49
50 #[wasm_bindgen(method, js_name = copyFileSync, structural)]
51 fn copyFileSync(me: &NodeFs, path_src: &str, path_dest: &str);
52
53 #[wasm_bindgen(method, js_name = renameSync, structural)]
54 fn renameSync(me: &NodeFs, path_src: &str, path_dest: &str);
55
56 #[wasm_bindgen(method, js_name = unlinkSync, structural)]
57 fn unlinkSync(me: &NodeFs, path: &str);
58}