MCPcopy Create free account
hub / github.com/cloudflare/computer / createThinkCompatibility

Function createThinkCompatibility

packages/computer/src/workspace.ts:1126–1194  ·  view source on GitHub ↗
(
  fs: ThinkWorkspaceFilesystem,
)

Source from the content-addressed store, hash-verified

1124}
1125
1126export function createThinkCompatibility(
1127 fs: ThinkWorkspaceFilesystem,
1128): ThinkWorkspaceCompatibility {
1129 return {
1130 async readFile(path) {
1131 try {
1132 return await fs.readFile(path, "utf8");
1133 } catch (err) {
1134 if (isEnoent(err)) return null;
1135 throw err;
1136 }
1137 },
1138 async readFileBytes(path) {
1139 try {
1140 return await drainBytes(await fs.readFile(path));
1141 } catch (err) {
1142 if (isEnoent(err)) return null;
1143 throw err;
1144 }
1145 },
1146 async writeFile(path, content) {
1147 await fs.writeFile(path, content);
1148 },
1149 async readDir(dir, opts) {
1150 const entries = await fs.readdir(dir);
1151 const offset = opts?.offset ?? 0;
1152 const limit = opts?.limit ?? entries.length;
1153 return entries.slice(offset, offset + limit).map((entry) =>
1154 toThinkFileInfo({
1155 path: joinPath(dir, entry.name),
1156 name: entry.name,
1157 size: 0,
1158 mtime: 0,
1159 isDirectory: entry.isDirectory,
1160 isFile: entry.isFile,
1161 }),
1162 );
1163 },
1164 async rm(path, opts) {
1165 await fs.rm(path, opts);
1166 },
1167 async glob(pattern) {
1168 const { directory, relativePattern } = splitGlobPattern(pattern);
1169 const matches = await fs.find(directory, relativePattern);
1170 return matches.map((match) =>
1171 toThinkFileInfo({
1172 path: match.path,
1173 name: basename(match.path),
1174 size: 0,
1175 mtime: 0,
1176 isDirectory: match.type === "dir",
1177 isFile: match.type === "file",
1178 }),
1179 );
1180 },
1181 async mkdir(path, opts) {
1182 await fs.mkdir(path, opts);
1183 },

Callers 2

makeClientFunction · 0.85
constructorMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected