feat: readd FS API via new env API

This commit is contained in:
TopchetoEU 2023-12-27 13:14:46 +02:00
parent 802f2f3f52
commit 21534efd60
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4
2 changed files with 11 additions and 5 deletions

View File

@ -1,8 +1,17 @@
package me.topchetoeu.jscript.filesystem;
import me.topchetoeu.jscript.engine.Extensions;
import me.topchetoeu.jscript.engine.values.Symbol;
public interface Filesystem {
public static final Symbol ENV_KEY = Symbol.get("Environment.fs");
String normalize(String... path);
File open(String path, Mode mode) throws FilesystemException;
void create(String path, EntryType type) throws FilesystemException;
FileStat stat(String path) throws FilesystemException;
public static Filesystem get(Extensions exts) {
return exts.get(ENV_KEY);
}
}

View File

@ -25,11 +25,8 @@ public class FilesystemLib {
@Native public static final int SEEK_END = 2;
private static Filesystem fs(Context ctx) {
var env = ctx.environment();
if (env != null) {
var fs = ctx.environment().filesystem;
var fs = Filesystem.get(ctx);
if (fs != null) return fs;
}
throw EngineException.ofError("Current environment doesn't have a file system.");
}