Skip to content

DWebVault API

Jared Rice Sr edited this page Jul 11, 2018 · 1 revision

@dwebs/vault

A nodejs API for the dWeb (Distributed Web) which is compatible with dPack's and dBrowser's DPackVault API. Useful for testing and for writing apps that work in the browser and in nodejs.

varDWebVault=require('@dwebs/vault')// create a new vaultvarvault=awaitDWebVault.create({localPath: './my-dweb-vault-data',title: 'My dWeb Vault',description: 'A test of the core DWebVault API'})// load an existing vault from diskvarvault=awaitDWebVault.load({localPath: './my-dweb-vault-data'})// load an existing vault from the URL:varvault=newDWebVault(dwebURL,{localPath: './my-dweb-vault-data'})// using the instanceawaitvault.writeFile('hello.txt','world')varnames=awaitvault.readdir('/')console.log(names)// => ['hello.txt']

By default, @dwebs/vault stores the dWeb data in the localPath folder using the SLEEP format (dWeb's internal structure). If you want the folder to show the latest files (the dpack cli behavior) pass latest: true in the dpackOptions.

varvault=awaitDWebVault.create({localPath: './my-dweb-vault-data',dpackOptions: {latest: true}})varvault=awaitDWebVault.load({localPath: './my-dweb-vault-data',dpackOptions: {latest: true}})varvault=newDWebVault(dwebURL,{localPath: './my-dweb-vault-data',dpackOptions: {latest: true}})

You can also pass options through to @dpack/core with dpackOptions, or pass options to its .joinNetwork([opts]) method with netOptions:

varvault=newDWebVault(dwebURL,{localPath: './my-dweb-vault-data',dpackOptions: {live: true},netOptions: {upload: false}})

This will extend @dwebs/vault's defaults.

Differences from Browser API

  • This module adds the localPath parameter. Use the localPath to specify where the data for the vault should be stored. If not provided, the vault will be stored in memory.
  • This module also adds dpackOptions and netOptions to configure the @dpack/core usage.
  • This module also adds DWebVault.load() to read an vault from disk.
  • This module does yet not include DWebVault.fork.
  • This module does yet not include DWebVault.unlink.
  • This module will not include DWebVault.selectVault.
  • vault.getInfo() does not give a valid mtime or size.
  • networked: opt is not yet supported.

Quick API reference

Refer to the dWeb's DWebVault documentation.

varvault=newDWebVault(url,{localPath:,dpackOptions:,netOptions:})varvault=awaitDWebVault.create({localPath:,dpackOptions:,netOptions:,title:,description:,type:,author:,networked:})varvault=awaitDWebVault.load({localPath:,dpackOptions:,netOptions:})varkey=awaitDWebVault.resolveName(url)vault.urlawaitvault.configure({title:,description:,type:,author:,networked:})varinfo=awaitvault.getInfo({timeout:})varstat=awaitvault.stat(path,{timeout:})varcontent=awaitvault.readFile(path,{encoding:,timeout:})varnames=vault.readdir(path,{recursive:,stat:,timeout:})awaitvault.writeFile(path,data,encoding)awaitvault.mkdir(path)awaitvault.unlink(path)awaitvault.rmdir(path,{recursive:})varhistory=awaitvault.history({start:,end:,reverse:,timeout:})awaitvault.download(path,{timeout:})varemitter=vault.createFileActivityStream(pattern)varemitter=vault.createNetworkActivityStream()// node-only:vault._loadPromise// promise for when the vault is ready to usevault._close()// exit flock, close all files

Clone this wiki locally