Read file
Read a file from the currently loaded game project:
ts
import { Fs } from '@vaguevoid/tools'
// mime type of image will return a Blob
const contentsBlob = await Fs.readFile("assets/hello.png");
console.log(contentsBlob)
// mime type of json will return an object
const contentsObject = await Fs.readFile("assets/hello.json");
console.log(contentsObject)
// any other mime type will return a string
const contentsString = await Fs.readFile("assets/hello.txt");
console.log(contentsString)
Handle file not found:
ts
import { Fs } from "@vaguevoid/tools";
try {
const contents = await Fs.readFile("assets/does-not-exist.txt");
console.log(contents);
} catch (err: any) {
if (err.message.startsWith("RequestFailed404")) {
return new Thing({ id: "__root" })
} else {
console.error(err)
}
}