Skip to content

Commit

Permalink
feat(AtomicFileAdapter): Add support for fsync
Browse files Browse the repository at this point in the history
  • Loading branch information
Belphemur committed Aug 1, 2022
1 parent 002a72a commit 4a51239
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/adapter/file/AtomicFileAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import {readFile, writeFile} from "atomically";

export class AtomicFileAdapter implements IFileAdapter<string> {
public readonly filename: string;
private fsync: boolean;

constructor(filename: string) {
constructor(filename: string, fsync: boolean) {
this.filename = filename;
this.fsync = fsync;
}

async readAsync(): Promise<string | null> {
Expand All @@ -23,7 +25,8 @@ export class AtomicFileAdapter implements IFileAdapter<string> {

writeAsync(data: string): Promise<void> {
return writeFile(this.filename, data, {
encoding: 'utf-8'
encoding: 'utf-8',
fsync: this.fsync
})
}
}

0 comments on commit 4a51239

Please sign in to comment.