Commit cdf03ca4 authored by Aral Balkan's avatar Aral Balkan
Browse files

Replace fs-extra with fs and fs/promises in JSTable class

parent e0c83b12
......@@ -13,7 +13,8 @@
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
import fs from 'fs-extra'
import fs from 'fs'
import fsPromises from 'fs/promises'
import path from 'path'
import EventEmitter from 'events'
......@@ -103,10 +104,10 @@ export default class JSTable extends EventEmitter {
const t1 = performance.now()
log(` 💾 ❨JSDB❩ Compacting and persisting table ${this.tableName}…`)
const compactedFilePath = `${this.tablePath}.compacted.tmp`
fs.removeSync(compactedFilePath)
fs.rmSync(compactedFilePath, {recursive: true, force: true})
delete this.#data.__id__ // We don’t want to set the ID twice as the creation process will.
this._create(compactedFilePath)
fs.moveSync(compactedFilePath, this.tablePath, { overwrite: true })
fs.renameSync(compactedFilePath, this.tablePath, { overwrite: true })
log(` 💾 ❨JSDB❩ ╰─ Compacted and persisted table in ${(performance.now() - t1).toFixed(3)} ms.`)
}
......@@ -128,7 +129,7 @@ export default class JSTable extends EventEmitter {
async delete () {
log(` 💾 ❨JSDB❩ Deleting table ${this.tableName}…`)
await this.close()
await fs.remove(this.tablePath)
await fsPromises.rm(this.tablePath, {recursive: true, force: true})
log(` 💾 ❨JSDB❩ ╰─ Table in ${this.tableName} deleted.`)
this.emit('delete', this.#dataProxy)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment