fixed-block-store
Advanced tools
+26
-6
@@ -5,2 +5,4 @@ const fs = require('fs') | ||
| const MAX_BATCH_SIZE = 131072 | ||
| class FixedBlock { | ||
@@ -11,2 +13,3 @@ constructor (store, index) { | ||
| this.userData = null | ||
| this.buffer = null | ||
@@ -50,3 +53,3 @@ this.loading = null | ||
| module.exports = class FixedBlockStore extends ReadyResource { | ||
| constructor (filename, { maxCache = 128, readBatch = 4 } = {}) { | ||
| constructor (filename, { maxCache = 128, readBatch = 1 } = {}) { | ||
| super() | ||
@@ -77,4 +80,3 @@ | ||
| const active = this.blocks.size - this.idle.length - this.gc.length | ||
| if (active < this.maxCache) return | ||
| if (this.gc.length + this.idle.length < this.maxCache) return | ||
@@ -156,2 +158,3 @@ // just pick anyone from the gc set that is not queued for flushing | ||
| let bytesMissing = blocks.length * 4096 | ||
| fs.writev(fd, blocks, pos, onwrite) | ||
@@ -196,3 +199,3 @@ | ||
| if (q.index === index + batch.length) { | ||
| if (batch.length < MAX_BATCH_SIZE && q.index === index + batch.length) { | ||
| batch.push(q.buffer) | ||
@@ -217,2 +220,13 @@ continue | ||
| async info () { | ||
| if (this.opened === false) await this.ready() | ||
| return new Promise((resolve, reject) => { | ||
| fs.fstat(this.fd, function (err, st) { | ||
| if (err) return reject(err) | ||
| resolve({ blocks: Math.floor(st.size / 4096) }) | ||
| }) | ||
| }) | ||
| } | ||
| async flush () { | ||
@@ -247,5 +261,9 @@ if (this.opened === false) await this.ready() | ||
| this._maybeGC() | ||
| for (let i = index - 1; i >= start; i--) { | ||
| if (this.blocks.has(i)) break | ||
| batch.push(new FixedBlock(this, i)) | ||
| const blk = new FixedBlock(this, i) | ||
| blk.close() | ||
| batch.push(blk) | ||
| } | ||
@@ -257,3 +275,5 @@ | ||
| if (this.blocks.has(i)) break | ||
| batch.push(new FixedBlock(this, i)) | ||
| const blk = new FixedBlock(this, i) | ||
| blk.close() | ||
| batch.push(blk) | ||
| } | ||
@@ -260,0 +280,0 @@ |
+1
-1
| { | ||
| "name": "fixed-block-store", | ||
| "version": "0.0.0", | ||
| "version": "0.0.1", | ||
| "description": "Fast block store to access/update 4kb disk pages", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
9851
4.44%251
6.36%