Skip to content
This repository was archived by the owner on Apr 16, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 58 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,61 @@
'use strict'

const readWrite = require('./read-write')
const exists = require('./exists')
const remove = require('./remove')

module.exports = (common) => {
readWrite(common)
exists(common)
remove(common)
const createWrite = require('pull-write')
const pull = require('pull-stream')

module.exports = class MemoryBlobStore {
constructor () {
this.store = {}
}

write (key, cb) {
cb = cb || (() => {})

if (!key) {
return cb(new Error('Missing key'))
}

this.store[key] = new Buffer([])

return createWrite((data, cb) => {
this.store[key] = Buffer.concat(
[this.store[key]].concat(data)
)
cb()
}, null, 100, cb)
}

read (key) {
if (!key) {
return pull.error(new Error('Missing key'))
}

const place = this.store[key]
if (place) {
return pull.values([this.store[key]])
}

return pull.error(new Error(`Unkown key ${key}`))
}

exists (key, cb) {
cb = cb || (() => {})

if (!key) {
return cb(new Error('Missing key'))
}

cb(null, Boolean(this.store[key]))
}

remove (key, cb) {
cb = cb || (() => {})

if (!key) {
return cb(new Error('Missing key'))
}

delete this.store[key]
cb()
}
}
61 changes: 0 additions & 61 deletions src/reference.js

This file was deleted.

11 changes: 11 additions & 0 deletions src/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict'

const readWrite = require('./read-write')
const exists = require('./exists')
const remove = require('./remove')

module.exports = (common) => {
readWrite(common)
exists(common)
remove(common)
}