Skip to content

Commit

Permalink
Platform: add sync (fsync) (#4345)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanniser authored Feb 1, 2025
1 parent e374d94 commit c9175ae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/spicy-pumas-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@effect/platform-node-shared": patch
"@effect/platform": patch
---

Addition of `sync` property to `FileSystem.File` representing the `fsync` syscall.
10 changes: 10 additions & 0 deletions packages/platform-node-shared/src/internal/fileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ const makeFile = (() => {
handleBadArgument("truncate")
)

const nodeSync = effectify(
NFS.fsync,
handleErrnoException("FileSystem", "sync"),
handleBadArgument("sync")
)

const nodeWriteFactory = (method: string) =>
effectify(
NFS.write,
Expand All @@ -236,6 +242,10 @@ const makeFile = (() => {
return Effect.map(nodeStat(this.fd), makeFileInfo)
}

get sync() {
return nodeSync(this.fd)
}

seek(offset: FileSystem.SizeInput, from: FileSystem.SeekMode) {
const offsetSize = FileSystem.Size(offset)
return this.semaphore.withPermits(1)(
Expand Down
1 change: 1 addition & 0 deletions packages/platform/src/FileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ export interface File {
readonly fd: File.Descriptor
readonly stat: Effect.Effect<File.Info, PlatformError>
readonly seek: (offset: SizeInput, from: SeekMode) => Effect.Effect<void>
readonly sync: Effect.Effect<void, PlatformError>
readonly read: (buffer: Uint8Array) => Effect.Effect<Size, PlatformError>
readonly readAlloc: (size: SizeInput) => Effect.Effect<Option<Uint8Array>, PlatformError>
readonly truncate: (length?: SizeInput) => Effect.Effect<void, PlatformError>
Expand Down

0 comments on commit c9175ae

Please sign in to comment.