MCPcopy Create free account
hub / github.com/effect-app/libs / FileImpl

Class FileImpl

repos/effect/packages/platform-node-shared/src/NodeFileSystem.ts:238–372  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

236 )
237
238 const nodeSync = effectify(
239 NFS.fsync,
240 handleErrnoException("FileSystem", "sync"),
241 handleBadArgument("sync")
242 )
243
244 const nodeWriteFactory = (method: string) =>
245 effectify(
246 NFS.write,
247 handleErrnoException("FileSystem", method),
248 handleBadArgument(method)
249 )
250 const nodeWrite = nodeWriteFactory("write")
251 const nodeWriteAll = nodeWriteFactory("writeAll")
252
253 class FileImpl implements FileSystem.File {
254 readonly [FileSystem.FileTypeId]: typeof FileSystem.FileTypeId
255 readonly fd: number
256 private readonly append: boolean
257
258 private position: bigint = BigInt(0)
259
260 constructor(
261 fd: number,
262 append: boolean
263 ) {
264 this[FileSystem.FileTypeId] = FileSystem.FileTypeId
265 this.fd = fd
266 this.append = append
267 }
268
269 get stat() {
270 return Effect.map(nodeStat(this.fd), makeFileInfo)
271 }
272
273 get sync() {
274 return nodeSync(this.fd)
275 }
276
277 seek(offset: FileSystem.SizeInput, from: FileSystem.SeekMode) {
278 const offsetSize = FileSystem.Size(offset)
279 return Effect.sync(() => {
280 if (from === "start") {
281 this.position = offsetSize
282 } else if (from === "current") {
283 this.position = this.position + offsetSize
284 }
285
286 return FileSystem.Size(this.position)
287 })
288 }
289
290 read(buffer: Uint8Array) {
291 return Effect.suspend(() => {
292 const position = this.position
293 return Effect.map(
294 nodeRead(this.fd, { buffer, position }),
295 (bytesRead) => {

Callers

nothing calls this directly

Calls 1

BigIntInterface · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…