immediate-chunk-store
Advanced tools
Comparing version 2.0.0 to 2.1.0
30
index.js
@@ -0,1 +1,4 @@ | ||
// TODO: remove when window.queueMicrotask() is well supported | ||
const queueMicrotask = require('queue-microtask') | ||
class ImmediateStore { | ||
@@ -24,9 +27,20 @@ constructor (store) { | ||
const start = (opts && opts.offset) || 0 | ||
const end = opts && opts.length && (start + opts.length) | ||
let memoryBuffer = this.mem[index] | ||
const buf = this.mem[index] | ||
if (buf) return nextTick(cb, null, opts ? buf.slice(start, end) : buf) | ||
// if the chunk isn't in the immediate memory cache | ||
if (!memoryBuffer) { | ||
return this.store.get(index, opts, cb) | ||
} | ||
this.store.get(index, opts, cb) | ||
if (opts) { | ||
const start = opts.offset || 0 | ||
const end = opts.length ? (start + opts.length) : memoryBuffer.length | ||
memoryBuffer = memoryBuffer.slice(start, end) | ||
} | ||
// queueMicrotask to ensure the function is async | ||
queueMicrotask(() => { | ||
if (cb) cb(null, memoryBuffer) | ||
}) | ||
} | ||
@@ -43,8 +57,2 @@ | ||
function nextTick (cb, err, val) { | ||
process.nextTick(() => { | ||
if (cb) cb(err, val) | ||
}) | ||
} | ||
module.exports = ImmediateStore |
{ | ||
"name": "immediate-chunk-store", | ||
"description": "Immediate put/get for abstract-chunk-store compliant stores", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"author": { | ||
@@ -13,6 +13,8 @@ "name": "Feross Aboukhadijeh", | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"queue-microtask": "^1.1.2" | ||
}, | ||
"devDependencies": { | ||
"abstract-chunk-store": "^1.0.0", | ||
"fs-chunk-store": "^1.3.0", | ||
"fs-chunk-store": "^2.0.0", | ||
"memory-chunk-store": "^1.1.1", | ||
@@ -19,0 +21,0 @@ "standard": "*", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5088
43
1
+ Addedqueue-microtask@^1.1.2
+ Addedqueue-microtask@1.2.3(transitive)