feat: readd FS API via new env API
This commit is contained in:
parent
802f2f3f52
commit
21534efd60
@ -1,8 +1,17 @@
|
|||||||
package me.topchetoeu.jscript.filesystem;
|
package me.topchetoeu.jscript.filesystem;
|
||||||
|
|
||||||
|
import me.topchetoeu.jscript.engine.Extensions;
|
||||||
|
import me.topchetoeu.jscript.engine.values.Symbol;
|
||||||
|
|
||||||
public interface Filesystem {
|
public interface Filesystem {
|
||||||
|
public static final Symbol ENV_KEY = Symbol.get("Environment.fs");
|
||||||
|
|
||||||
String normalize(String... path);
|
String normalize(String... path);
|
||||||
File open(String path, Mode mode) throws FilesystemException;
|
File open(String path, Mode mode) throws FilesystemException;
|
||||||
void create(String path, EntryType type) throws FilesystemException;
|
void create(String path, EntryType type) throws FilesystemException;
|
||||||
FileStat stat(String path) throws FilesystemException;
|
FileStat stat(String path) throws FilesystemException;
|
||||||
|
|
||||||
|
public static Filesystem get(Extensions exts) {
|
||||||
|
return exts.get(ENV_KEY);
|
||||||
|
}
|
||||||
}
|
}
|
@ -25,11 +25,8 @@ public class FilesystemLib {
|
|||||||
@Native public static final int SEEK_END = 2;
|
@Native public static final int SEEK_END = 2;
|
||||||
|
|
||||||
private static Filesystem fs(Context ctx) {
|
private static Filesystem fs(Context ctx) {
|
||||||
var env = ctx.environment();
|
var fs = Filesystem.get(ctx);
|
||||||
if (env != null) {
|
if (fs != null) return fs;
|
||||||
var fs = ctx.environment().filesystem;
|
|
||||||
if (fs != null) return fs;
|
|
||||||
}
|
|
||||||
throw EngineException.ofError("Current environment doesn't have a file system.");
|
throw EngineException.ofError("Current environment doesn't have a file system.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user