()
| 77 | } |
| 78 | |
| 79 | async init() { |
| 80 | if (this.fd != null) return; |
| 81 | let locked = false; |
| 82 | try { |
| 83 | if (lockfile.checkSync(this.path)) locked = true; |
| 84 | } catch {} |
| 85 | if (locked) { |
| 86 | throw new Error("File is locked"); |
| 87 | } |
| 88 | try { |
| 89 | this.fd = await fs.open(this.path, "w+"); |
| 90 | this.releaseLock = await lockfile.lock(this.path); |
| 91 | await fs.ftruncate(this.fd, this.size); |
| 92 | } catch (e) { |
| 93 | if (typeof this.releaseLock === "function") await this.releaseLock(); |
| 94 | this.releaseLock = undefined; |
| 95 | throw e; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | async write(offset: number, chunk: Buffer) { |
| 100 | this.lastUpdate = Date.now(); |
no test coverage detected