hyperdrive
Advanced tools
Comparing version 11.0.0-alpha.15 to 11.0.0-alpha.16
70
index.js
@@ -31,3 +31,3 @@ const Hyperbee = require('hyperbee') | ||
this.ready().catch(noop) | ||
this.ready().catch(safetyCatch) | ||
} | ||
@@ -96,2 +96,3 @@ | ||
await this.db.close() | ||
await this.files.close() // workaround to flush the batches for now. TODO: kill the sub! | ||
} catch (e) { | ||
@@ -150,2 +151,5 @@ safetyCatch(e) | ||
this.db.metadata.contentFeed = this.blobs.core.key | ||
this.emit('blobs', this.blobs) | ||
this.emit('content-key', blobsCore.key) | ||
} | ||
@@ -158,3 +162,3 @@ | ||
this._openingBlobs = this._openBlobsFromHeader() | ||
this._openingBlobs.catch(noop) | ||
this._openingBlobs.catch(safetyCatch) | ||
} | ||
@@ -190,22 +194,64 @@ } | ||
async del (name) { | ||
if (!this.opened) await this.ready() | ||
return this.files.del(normalizePath(name)) | ||
} | ||
async clear (name) { | ||
const node = await this.entry(name) | ||
if (node === null) return | ||
async clear (name, opts) { | ||
if (!this.opened) await this.ready() | ||
await this.getBlobs() | ||
await this.blobs.clear(node.value.blob) | ||
const diffing = !!(opts && opts.diff) | ||
let node = null | ||
try { | ||
node = await this.entry(name, { wait: false }) | ||
} catch { | ||
// do nothing, prop not available | ||
} | ||
const infoBefore = diffing === true | ||
? await this.blobs.core.info({ storage: true }) | ||
: null | ||
if (node !== null && this.blobs !== null) { | ||
await this.blobs.clear(node.value.blob) | ||
} | ||
if (diffing === false) return null | ||
const infoAfter = await this.blobs.core.info({ storage: true }) | ||
return { | ||
blocks: infoBefore.storage.blocks - infoAfter.storage.blocks | ||
} | ||
} | ||
async clearAll (opts) { | ||
if (!this.opened) await this.ready() | ||
const diffing = !!(opts && opts.diff) | ||
const infoBefore = diffing === true | ||
? await this.blobs.core.info({ storage: true }) | ||
: null | ||
if (this.blobs !== null) { | ||
await this.blobs.core.clear(0, this.blobs.core.length) | ||
} | ||
if (diffing === false) return null | ||
const infoAfter = await this.blobs.core.info({ storage: true }) | ||
return { | ||
blocks: infoBefore.storage.blocks - infoAfter.storage.blocks | ||
} | ||
} | ||
async symlink (name, dst, { metadata = null } = {}) { | ||
if (!this.opened) await this.ready() | ||
return this.files.put(normalizePath(name), { executable: false, linkname: dst, blob: null, metadata }) | ||
} | ||
entry (name) { | ||
entry (name, opts) { | ||
return typeof name === 'string' | ||
? this.files.get(normalizePath(name)) | ||
? this.files.get(normalizePath(name), opts) | ||
: Promise.resolve(name) | ||
@@ -471,4 +517,2 @@ } | ||
function noop () {} | ||
function makeBee (key, corestore, onwait) { | ||
@@ -475,0 +519,0 @@ const metadataOpts = key |
{ | ||
"name": "hyperdrive", | ||
"version": "11.0.0-alpha.15", | ||
"version": "11.0.0-alpha.16", | ||
"description": "Hyperdrive is a secure, real-time distributed file system", | ||
@@ -17,4 +17,4 @@ "main": "index.js", | ||
}, | ||
"author": "Mathias Buus (@mafintosh)", | ||
"license": "MIT", | ||
"author": "Holepunch", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
@@ -21,0 +21,0 @@ "url": "https://github.com/holepunchto/hyperdrive-next/issues" |
@@ -138,6 +138,24 @@ # Hyperdrive | ||
#### `await drive.clear(path)` | ||
#### `const cleared = await drive.clear(path, [options])` | ||
Deletes the blob from storage to free up space, but the file structure reference is kept. | ||
`options` include: | ||
```js | ||
{ | ||
diff: false // Returned `cleared` bytes object is null unless you enable this | ||
} | ||
``` | ||
#### `const cleared = await drive.clearAll([options])` | ||
Deletes all the blobs from storage to free up space, similar to how `drive.clear()` works. | ||
`options` include: | ||
```js | ||
{ | ||
diff: false // Returned `cleared` bytes object is null unless you enable this | ||
} | ||
``` | ||
#### `await drive.symlink(path, linkname)` | ||
@@ -295,1 +313,5 @@ | ||
[store-replicate-docs]: https://github.com/holepunchto/corestore#const-stream--storereplicateoptsorstream | ||
## License | ||
Apache-2.0 |
Sorry, the diff of this file is not supported yet
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
33742
405
316