@composio/core
Version:

45 lines (43 loc) • 1.11 kB
JavaScript
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
//#region src/platform/node.ts
/**
* Node.js platform implementation.
* Provides full file system and OS operations using Node.js built-in modules.
*/
const platform = {
supportsFileSystem: true,
homedir() {
try {
return os.homedir();
} catch {
return null;
}
},
joinPath(...paths) {
return path.join(...paths);
},
basename(filePath) {
return path.basename(filePath);
},
existsSync(filePath) {
return fs.existsSync(filePath);
},
mkdirSync(dirPath) {
fs.mkdirSync(dirPath, { recursive: true });
},
readFileSync(filePath, encoding) {
if (encoding === void 0) {
const buf = fs.readFileSync(filePath, { encoding: null });
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
}
return fs.readFileSync(filePath, { encoding });
},
writeFileSync(filePath, content, encoding) {
if (encoding && typeof content === "string") fs.writeFileSync(filePath, content, { encoding });
else fs.writeFileSync(filePath, content);
}
};
//#endregion
export { platform };