()
| 176 | } |
| 177 | |
| 178 | function createVfsHandlers() { |
| 179 | return { |
| 180 | __proto__: null, |
| 181 | |
| 182 | // ==================== Sync path-based read ops ==================== |
| 183 | |
| 184 | existsSync(path) { |
| 185 | const pathStr = toPathStr(path); |
| 186 | if (pathStr === null) return undefined; |
| 187 | const r = findVFSForExists(pathStr); |
| 188 | return r !== null ? r.exists : undefined; |
| 189 | }, |
| 190 | readFileSync(path, options) { |
| 191 | if (typeof path === 'number') { |
| 192 | const vfd = getVirtualFd(path); |
| 193 | if (vfd) { |
| 194 | const enc = typeof options === 'string' ? options : options?.encoding; |
| 195 | if (enc && enc !== 'buffer') assertEncoding(enc); |
| 196 | return vfd.entry.readFileSync(options); |
| 197 | } |
| 198 | return undefined; |
| 199 | } |
| 200 | const pathStr = toPathStr(path); |
| 201 | if (pathStr === null) return undefined; |
| 202 | const enc = typeof options === 'string' ? options : options?.encoding; |
| 203 | if (enc && enc !== 'buffer') assertEncoding(enc); |
| 204 | return findVFSWith(pathStr, 'open', (vfs, n) => vfs.readFileSync(n, options)); |
| 205 | }, |
| 206 | readdirSync(path, options) { |
| 207 | const result = vfsRead(path, 'scandir', (vfs, n) => vfs.readdirSync(n, options)); |
| 208 | if (result !== undefined && options?.encoding === 'buffer' && !options?.withFileTypes) { |
| 209 | for (let i = 0; i < result.length; i++) { |
| 210 | if (typeof result[i] === 'string') result[i] = Buffer.from(result[i]); |
| 211 | } |
| 212 | } |
| 213 | return result; |
| 214 | }, |
| 215 | lstatSync(path, options) { |
| 216 | const pathStr = toPathStr(path); |
| 217 | if (pathStr === null) return undefined; |
| 218 | const normalized = resolve(pathStr); |
| 219 | for (let i = 0; i < activeVFSList.length; i++) { |
| 220 | const vfs = activeVFSList[i]; |
| 221 | if (vfs.shouldHandle(normalized)) { |
| 222 | try { |
| 223 | return vfs.lstatSync(normalized, options); |
| 224 | } catch (e) { |
| 225 | if (e?.code === 'ENOENT' && options?.throwIfNoEntry === false) return undefined; |
| 226 | throw e; |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | return undefined; |
| 231 | }, |
| 232 | statSync(path, options) { |
| 233 | try { |
| 234 | return vfsRead(path, 'stat', (vfs, n) => vfs.statSync(n, options)); |
| 235 | } catch (err) { |
no test coverage detected
searching dependent graphs…