MCPcopy Create free account
hub / github.com/Effect-TS/effect / FileImpl

Class FileImpl

packages/platform/node-shared/src/NodeFileSystem.ts:253–387  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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) => {
296 const sizeRead = FileSystem.Size(bytesRead)
297 this.position = position + sizeRead
298 return sizeRead
299 }
300 )
301 })
302 }
303
304 readAlloc(size: FileSystem.SizeInput) {
305 const sizeNumber = Number(size)
306 return Effect.suspend(() => {
307 const buffer = Buffer.allocUnsafeSlow(sizeNumber)
308 const position = this.position
309 return Effect.map(
310 nodeReadAlloc(this.fd, { buffer, position }),

Callers

nothing calls this directly

Calls 1

BigIntInterface · 0.50

Tested by

no test coverage detected