hyperdrive
Advanced tools
Comparing version 11.0.0-alpha.18 to 11.0.0-alpha.19
21
index.js
@@ -7,2 +7,3 @@ const Hyperbee = require('hyperbee') | ||
const MirrorDrive = require('mirror-drive') | ||
const SubEncoder = require('sub-encoder') | ||
const ReadyResource = require('ready-resource') | ||
@@ -67,7 +68,7 @@ const safetyCatch = require('safety-catch') | ||
checkout (len) { | ||
_makeCheckout (snapshot) { | ||
return new Hyperdrive(this.corestore, this.key, { | ||
onwait: this._onwait, | ||
_checkout: this._checkout || this, | ||
_db: this.db.checkout(len), | ||
_db: snapshot, | ||
_files: null | ||
@@ -77,2 +78,6 @@ }) | ||
checkout (version) { | ||
return this._makeCheckout(this.db.checkout(version)) | ||
} | ||
batch () { | ||
@@ -251,2 +256,14 @@ return new Hyperdrive(this.corestore, this.key, { | ||
watch (folder) { | ||
folder = normalizePath(folder || '/') | ||
if (folder.endsWith('/')) folder = folder.slice(0, -1) | ||
const encoder = new SubEncoder() | ||
const files = encoder.sub('files', this.db.keyEncoding) | ||
const options = { map: (snap) => this._makeCheckout(snap) } | ||
return this.db.watch({ gt: files.encode(folder + '/'), lt: files.encode(folder + '0') }, options) | ||
} | ||
diff (length, folder, opts) { | ||
@@ -253,0 +270,0 @@ if (typeof folder === 'object' && folder && !opts) return this.diff(length, null, folder) |
{ | ||
"name": "hyperdrive", | ||
"version": "11.0.0-alpha.18", | ||
"version": "11.0.0-alpha.19", | ||
"description": "Hyperdrive is a secure, real-time distributed file system", | ||
@@ -24,3 +24,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"hyperbee": "^2.1.1", | ||
"hyperbee": "^2.11.1", | ||
"hyperblobs": "^2.3.0", | ||
@@ -32,2 +32,3 @@ "is-options": "^1.0.2", | ||
"streamx": "^2.12.4", | ||
"sub-encoder": "^2.1.0", | ||
"unix-path-resolve": "^1.0.2" | ||
@@ -34,0 +35,0 @@ }, |
@@ -209,2 +209,26 @@ # Hyperdrive | ||
#### `const watcher = db.watch([folder])` | ||
Returns an iterator that listens on `folder` to yield changes, by default on `/`. | ||
Usage example: | ||
```js | ||
for await (const [current, previous] of watcher) { | ||
console.log(current.version) | ||
console.log(previous.version) | ||
} | ||
``` | ||
Those `current` and `previous` are snapshots that are auto-closed before next value. | ||
Don't close those snapshots yourself because they're used internally, let them be auto-closed. | ||
`await watcher.ready()` | ||
Waits until the watcher is loaded and detecting changes. | ||
`await watcher.destroy()` | ||
Stops the watcher. You could also stop it by using `break` in the loop. | ||
#### `const rs = drive.createReadStream(path, [options])` | ||
@@ -211,0 +235,0 @@ |
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
34999
414
348
9
+ Addedsub-encoder@^2.1.0
+ Addedsub-encoder@2.1.3(transitive)
Updatedhyperbee@^2.11.1