orbit-db-storage-adapter
Advanced tools
Comparing version 0.4.0 to 0.4.1
{ | ||
"name": "orbit-db-storage-adapter", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "OrbitDB adapter for any abstract-leveldown compliant storage", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -40,5 +40,4 @@ # OrbitDB Storage Adapter | ||
const leveldownOptions = {} | ||
const Storage = require('orbit-db-storage-adapter')(leveldown) | ||
const storage = require('orbit-db-storage-adapter')(leveldown, leveldownOptions) | ||
const storage = new Storage(leveldown, leveldownOptions) // These options passed to leveldown factory | ||
const levelupOptions = {} // see below | ||
@@ -45,0 +44,0 @@ store = await storage.createStore(location, levelupOptions) // These options passed to levelup instance |
@@ -7,6 +7,21 @@ 'use strict' | ||
/* | ||
* createIfMissing (boolean, default: true): If true, will initialise an empty database at the specified location if one doesn't already exist. If false and a database doesn't exist you will receive an error in your open() callback and your database won't open. | ||
* | ||
* errorIfExists (boolean, default: false): If true, you will receive an error in your open() callback if the database exists at the specified location. | ||
* | ||
* compression (boolean, default: true): If true, all compressible data will be run through the Snappy compression algorithm before being stored. Snappy is very fast and shouldn't gain much speed by disabling so leave this on unless you have good reason to turn it off. | ||
* | ||
* cacheSize (number, default: 8 * 1024 * 1024 = 8MB): The size (in bytes) of the in-memory LRU cache with frequently used uncompressed block contents. | ||
*/ | ||
class Storage { | ||
constructor (storage, options) { | ||
constructor (storage, options = { | ||
createIfMissing: true, | ||
errorIfExists: false, | ||
compression: true, | ||
cacheSize: 8 * 1024 * 1024 } | ||
) { | ||
this.storage = storage | ||
this.leveldownOptions = options | ||
this.options = { down: options } | ||
} | ||
@@ -16,16 +31,19 @@ | ||
return new Promise((resolve, reject) => { | ||
const db = this.storage(directory, this.leveldownoptions) | ||
this.options.up = options | ||
this.preCreate(directory, this.options).then(() => { | ||
const db = this.storage(directory, this.options.down) | ||
// For compatibility with older abstract-leveldown stores | ||
if (!db.status) db.status = 'unknown-shim' | ||
if (!db.location) db.location = directory | ||
// For compatibility with older abstract-leveldown stores | ||
if (!db.status) db.status = 'unknown-shim' | ||
if (!db.location) db.location = directory | ||
const store = levelup(db, options) | ||
store.open((err) => { | ||
if (err) { | ||
return reject(err) | ||
} | ||
// More backwards compatibility | ||
if (db.status === 'unknown-shim') db.status = 'open' | ||
resolve(store) | ||
const store = levelup(db, options) | ||
store.open((err) => { | ||
if (err) { | ||
return reject(err) | ||
} | ||
// More backwards compatibility | ||
if (db.status === 'unknown-shim') db.status = 'open' | ||
resolve(store) | ||
}) | ||
}) | ||
@@ -48,4 +66,6 @@ }) | ||
} | ||
async preCreate (directory, options) {} // to be overridden | ||
} | ||
module.exports = (storage, options) => new Storage(storage, options) |
Sorry, the diff of this file is too big to display
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
120657
655
62