Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

immediate-chunk-store

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immediate-chunk-store - npm Package Compare versions

Comparing version 1.0.8 to 2.0.0

65

index.js

@@ -1,49 +0,48 @@

module.exports = ImmediateStore
class ImmediateStore {
constructor (store) {
this.store = store
this.chunkLength = store.chunkLength
function ImmediateStore (store) {
if (!(this instanceof ImmediateStore)) return new ImmediateStore(store)
if (!this.store || !this.store.get || !this.store.put) {
throw new Error('First argument must be abstract-chunk-store compliant')
}
this.store = store
this.chunkLength = store.chunkLength
this.mem = []
}
if (!this.store || !this.store.get || !this.store.put) {
throw new Error('First argument must be abstract-chunk-store compliant')
put (index, buf, cb) {
this.mem[index] = buf
this.store.put(index, buf, err => {
this.mem[index] = null
if (cb) cb(err)
})
}
this.mem = []
}
get (index, opts, cb) {
if (typeof opts === 'function') return this.get(index, null, opts)
ImmediateStore.prototype.put = function (index, buf, cb) {
var self = this
self.mem[index] = buf
self.store.put(index, buf, function (err) {
self.mem[index] = null
if (cb) cb(err)
})
}
const start = (opts && opts.offset) || 0
const end = opts && opts.length && (start + opts.length)
ImmediateStore.prototype.get = function (index, opts, cb) {
if (typeof opts === 'function') return this.get(index, null, opts)
const buf = this.mem[index]
if (buf) return nextTick(cb, null, opts ? buf.slice(start, end) : buf)
var start = (opts && opts.offset) || 0
var end = opts && opts.length && (start + opts.length)
this.store.get(index, opts, cb)
}
var buf = this.mem[index]
if (buf) return nextTick(cb, null, opts ? buf.slice(start, end) : buf)
close (cb) {
this.store.close(cb)
}
this.store.get(index, opts, cb)
destroy (cb) {
this.store.destroy(cb)
}
}
ImmediateStore.prototype.close = function (cb) {
this.store.close(cb)
}
ImmediateStore.prototype.destroy = function (cb) {
this.store.destroy(cb)
}
function nextTick (cb, err, val) {
process.nextTick(function () {
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": "1.0.8",
"version": "2.0.0",
"author": {

@@ -18,3 +18,3 @@ "name": "Feross Aboukhadijeh",

"memory-chunk-store": "^1.1.1",
"standard": "^6.0.4",
"standard": "*",
"tape": "^4.1.0"

@@ -39,4 +39,4 @@ },

"scripts": {
"test": "standard && node test"
"test": "standard && tape test/*.js"
}
}

@@ -1,2 +0,2 @@

# immediate-chunk-store [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url]
# immediate-chunk-store [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]

@@ -9,5 +9,9 @@ [travis-image]: https://img.shields.io/travis/feross/immediate-chunk-store/master.svg

[downloads-url]: https://npmjs.org/package/immediate-chunk-store
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
[standard-url]: https://standardjs.com
#### Immediate put/get for [abstract-chunk-store](https://github.com/mafintosh/abstract-chunk-store) compliant stores
[![abstract chunk store](https://cdn.rawgit.com/mafintosh/abstract-chunk-store/master/badge.svg)](https://github.com/mafintosh/abstract-chunk-store)
Makes `store.put()` chunks immediately available for `store.get()`, even before the

@@ -31,3 +35,3 @@ `store.put()` callback is called. Data is stored in memory until the `store.put()`

store.put(0, new Buffer('abc'), function () { /* yolo */ })
store.put(0, Buffer.from('abc'), function () { /* yolo */ })

@@ -34,0 +38,0 @@ // And now, get the same chunk out BEFORE the put is complete

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc