{"bugs":{"url":"https://github.com/datproject/sdk/issues"},"dist":{"shasum":"5d36fbfcbf648b7439843cce2e6300e0c1e5a653","tarball":"https://registry.npmjs.org/dat-sdk/-/dat-sdk-2.0.0-7.tgz","fileCount":6,"integrity":"sha512-KmhE7P7aKxEpEALeKWr5KSR2fU+CXfosq3RfqECvFfkKpNIthjB07+4r706GNmktPyVUlk37chkuVutOst1mVA==","signatures":[{"sig":"MEUCIHARYk8mjs/jcVT7ER5+I9T5XZl2Xtws519/S8yhlBbGAiEAz2cqAbYdCJcUZY/a2XY8P3DFU00thcl6zb275/oKokw=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":39466,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJetZryCRA9TVsSAnZWagAAv8oP/3HaHchpe/GeWbsGL6t5\nmfxbzoWRHmWm2rOoHtgK1zmxe56tcQzfa8NMIt8DHJVTWlNyqiqMXacuO+er\n39slIFnyqONsSK3XLE9tyfSBBLtfjp9wIj6Ej3joPmhWXFWZew6DeJlIC4AC\nlBaZ1/3g1MHN73deR2bjDziohyh2umm+iU4QI8nJELRV3G3acMWqJnMEi3Q+\n9JeQyEsTy2hRjmcFd0yWisvKUyNFm8t8b2CbuqnGDNI+bXVbdXUeIU32BvC0\nyNO/4w5FMc3741thbSt35PyujVLPh8NV3DMg5mkikz97Awi2ihAEgvTaTYMC\nv2V3Xmz82rSwPkCC6iSG/vZuU2gagl0EfVcprgaKPm5siNtI+zXi6zAquceA\nJuWjXe87IQ90Jl6OdrXjgX5Fk32LJjaXeLqPczxUjj2dX2zsOHhJuYOlHJ9t\nrI8Qj+2mxlCDzNUkKEjVF2zdhI6FXe8uQ77IUBw+13Eu6/EMY0AM93YMFF4/\nFvw8Ayc6sIGkldiTrLodC4j39E6SowShj1uunu2fWHDTC8v86FXaV1x6AIv6\nBOgj0IO6yuMOprmc+h6AYiemsfjrrQwwXWk+uTRAcvDRhkdVwBnRkpnI6SZS\nVTErIWOuK9s7WmaVttPK8XOaf1HU9WxCWHgzHt2R85LLSBQRsPOUBMKsiJmj\nSiDb\r\n=YoU2\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","name":"dat-sdk","author":{"name":"datproject"},"readme":"# sdk\nThe official Dat SDK\n\n[<img src=\"https://datproject.github.io/design/downloads/dat-logo.png\" align=\"right\" width=\"140\">][Dat Project]\n\n## Why use this?\n\nDat consists of a bunch of low level building blocks for working with data in distributed applications. Although this modularity makes it easy to mix and match pieces, it adds complexity when it comes to actually building something.\n\nThe Dat SDK combines the lower level pieces of the Dat ecosystem into high level APIs that you can use across platforms so that you can focus on your application rather than the gritty details of how it works.\n\n## Goals\n\n- High level API\n- Cross-platform with same codebase\n  - ✔ Node\n  - ✔ Web\n  - ✔ Electron\n  - React-Native (with [nodejs-mobile-react-native?](https://github.com/janeasystems/nodejs-mobile-react-native))\n\n## Installing Node\n\n[Node.js](https://nodejs.org/) / [Browserify](http://browserify.org/) workflows:\n\n```shell\nnpm install --save dat-sdk@next\n```\n\n```js\nconst SDK = require('dat-sdk')\n```\n\n## Building a bundle for Browsers\n\n```shell\ngit clone git@github.com:datproject/sdk.git\n\ncd sdk\n\n# Compile the SDK into a single JS file\nnpm run build\n\n# Copy `dat-sdk-bundle.js` into your project\n```\n\n```html\n<script src=\"dat-sdk-bundle.js\"></script>\n<script>\n  const SDK = window.datSDK\n  // Look at the examples from here\n</script>\n```\n\n## Compile with Browserify\n\n```\nnpm install --save-dev browserify\nnpm install --save dat-sdk@next\n```\n\nAdd this as the `build` command in your package.json\n\n```shell\nbrowserify index.js > bundle.js\n```\n\nThen you can use `bundle.js` in your project.\n\n## Compile with Webpack (webpack.config.js)\n\nTo bundle with webpack, you'll need to alias some dependencies.\n\n```js\nconst path = require('path')\n\nmodule.exports = {\n  entry: './index.js',\n  target: 'web',\n  resolve: {\n    alias: {\n      fs: 'graceful-fs',\n      'sodium-native': '@geut/sodium-javascript-plus',\n      'sodium-universal': '@geut/sodium-javascript-plus',\n      hyperswarm: 'hyperswarm-web',\n      util: './node_modules/util/util.js'\n    }\n  },\n  output: {\n    filename: 'bundle.js',\n    path: path.resolve(__dirname, 'dist')\n  }\n}\n```\n\nThen you can include `./dist/bundle.js` in your HTML page.\n\n## API/Examples\n\n```js\nconst SDK = require('dat-sdk')\n\nconst sdk = await SDK();\nconst {\n\tHypercore,\n\tHyperdrive,\n\tresolveName,\n\tclose\n} = sdk\n\n// Create a new Hyperdrive.\n// If you want to create a new archive, pass in a name for it\n// This will be used to derive a secret key\n// Every time you open a drive with that name it'll derive the same key\n// This uses a master key that's generated once per device\n// That means the same name will yield a different key on a different machine\nconst archive = Hyperdrive('My archive name', {\n  // This archive will disappear after the process exits\n  // This is here so that running the example doesn't clog up your history\n  persist: false,\n  // storage can be set to an instance of `random-access-*`\n  // const RAI = require('random-access-idb')\n  // otherwise it defaults to `random-access-web` in the browser\n  // and `random-access-file` in node\n  storage: null  //storage: RAI\n})\n\narchive.ready(() => {\n  const url = `dat://${archive.key.toString('hex')}`\n\n  // TODO: Save this for later!\n  console.log(`Here's your URL: ${url}`)\n\n  // Check out the hyperdrive docs for what you can do with it\n  // https://www.npmjs.com/package/hyperdrive#api\n  archive.writeFile('/example.txt', 'Hello World!', () => {\n    console.log('Written example file!')\n  })\n})\n\n// This example is currently broken because Beaker's website isn't on Dat 2 yet\nresolveName('dat://beakerbrowser.com', (err, key) => {\n  if (err) throw err\n  const archive = Hyperdrive(key)\n\n  archive.readFile('/dat.json', 'utf8', (err, data) => {\n    if (err) throw err\n    console.log(`Beaker's dat.json is ${data}`)\n\n    archive.close((err) => {\n      if (err) throw err\n      deleteStorage(archive.key, (e) => {\n        if (e) throw e\n        console.log('Deleted beaker storage')\n      })\n    })\n  })\n})\n\nconst SOME_URL = 'dat://0a9e202b8055721bd2bc93b3c9bbc03efdbda9cfee91f01a123fdeaadeba303e/'\n\nconst someArchive = Hyperdrive(SOME_URL)\n\nsomeArchive.readdir('/', console.log)}\n\n// Create a hypercore\n// Check out the hypercore docs for what you can do with it\n// https://github.com/mafintosh/hypercore\nconst myCore = Hypercore('my hypercore name', {\n  valueEncoding: 'json',\n  persist: false,\n  // storage can be set to an instance of `random-access-*`\n  // const RAI = require('random-access-idb')\n  // otherwise it defaults to `random-access-web` in the browser\n  // and `random-access-file` in node\n  storage: null  // storage: RAI\n})\n\n// Add some data to it\nmyCore.append(JSON.stringify({\n  name: 'Alice'\n}), () => {\n  // Use extension messages for sending extra data over the p2p connection\n  const discoveryCoreKey = 'dat://bee80ff3a4ee5e727dc44197cb9d25bf8f19d50b0f3ad2984cfe5b7d14e75de7'\n  const discoveryCore = new Hypercore(discoveryCoreKey)\n\n\t// Register the extension message handler\n\tconst extension = discoveryCore.registerExtension('discovery', {\n\t\t// Set the encoding type for messages\n\t\tencoding: 'binary',\n\t\tonmessage: (message, peer) => {\n\t\t\t// Recieved messages will be automatically decoded\n\t\t\tconsole.log('Got key from peer!', message)\n\n\t\t\tconst otherCore = new Hypercore(message, {\n        valueEncoding: 'json',\n        persist: false\n      })\n\n      // Render the peer's data from their core\n      otherCore.get(0, console.log)\n\t\t}\n\t})\n\n\t// When you find a peer tell them about your core\n\tdiscoveryCore.on('peer-add', (peer) => {\n\t\tconsole.log('Got a peer!')\n\t\textension.send(myCore.key, peer)\n\t})\n})\n\nconst hypertrie = require('hypertrie')\n\n// Pass in hypercores from the SDK into other dat data structures\n// Check out what you can do with hypertrie from there:\n// https://github.com/mafintosh/hypertrie\nconst trie = hypertrie(null, {\n  feed: new Hypercore('my trie core', {\n    persist: false\n  })\n})\n\ntrie.put('key', 'value', () => {\n  trie.get('key', (err, node) => {\n    console.log('Got key: ', node.key)\n    console.log('Loaded value from trie: ', node.value)\n  })\n})\n\n```\n\n## API\n\nThe API supports both promises and callbacks. Everywhere where you see `await`, you can instead pass a node-style callback.\n\n### `const {Hypercore, Hyperdrive, resolveName, getIdentity, deriveSecret, close} = await SDK(opts?)`\n\nCreates an instance of the Dat SDK based on the options.\n\n- `opts.storage`: An optional [random-access-storage](https://github.com/random-access-storage/random-access-storage) instance for storing data.\n- `opts.applicationName`: An optional name for the application using the SDK. This will automatically silo your data from other applications using the SDK and will store it in the appropriate place using [random-access-application](https://github.com/RangerMauve/random-access-application/)\n- `opts.corestore`: An optional [Corestore](https://github.com/andrewosh/corestore) instance for using as hypercore storage.\n- `opts.corestoreOpts`: Options to pass into Corestore when it's initialized.\n- `opts.swarmOpts`: This lets you configure [hyperswarm](https://github.com/hyperswarm/hyperswarm) and [hyperswarm-web](https://github.com/RangerMauve/hyperswarm-web)\n  - `maxPeers`: The maximum number of connections to keep for this swarm.\n  - `ephemeral **NODE**`: Set to `false` if this is going to be in a long running process on a server. \n  - `bootstap **NODE**`: An array of addresses to use for the DHT bootstraping\n  - `webrtcBootstrap: ['https://geut-webrtc-signal.herokuapp.com/'] **BROWSER**`: The WebRTC bootstrap server list used by [discovery-swarm-webrtc](https://github.com/geut/discovery-swarm-webrtc)\n  - `wsProxy: 'wss://hyperswarm.mauve.moe' **BROWSER**`: The Websocket proxy used for [hyperswarm-proxy-ws](https://github.com/RangerMauve/hyperswarm-proxy-ws)\n- `opts.driveOpts`: This lets you configure the behavior of [Hyperdrive](https://github.com/mafintosh/hyperdrive) instances\n  - `sparse: true`: Whether the history should be loaded on the fly instead of replicating the full history\n  - `persist: true`: Whether the data should be persisted to storage. Set to false to create in-memory archives\n- `opts.coreOpts`: This lets you configure the behavior of [Hypercore](https://github.com/mafintosh/hypercore) instances\n  - `sparse: true`: Whether the history should be loaded on the fly instead of replicating the full history\n  - `persist: true`: Whether the data should be persisted to storage. Set to false to create in-memory feeds\n  - `extensions`: The set of extension message types to use with this feed when replicating.\n  - `valueEncoding: 'json' | 'utf-8' | 'binary'`: The encoding to use for the data stored in the hypercore. Use JSON to store / retrieve objects.\n- `opts.dnsOpts`: Configure the [dat dns](https://github.com/datprotocol/dat-dns) resolution module. You probably shouldn't mess with this.\n  - `recordName: 'dat'`: name of .well-known file\n  - `protocolRegex: /^dat:\\/\\/([0-9a-f]{64})/i`: RegExp object for custom protocol\n  - `hashRegex: /^[0-9a-f]{64}?$/i`: RegExp object for custom hash i.e.\n  - `txtRegex: /\"?datkey=([0-9a-f]{64})\"?/i`: RegExp object for DNS TXT record of custom protocol\n\n### `await close()`\n\nThis closes all resources used by the SDK so you can safely end your process. `cb` will be invoked once resources are closed or if there's an error.\n\n### `const key = await resolveName(url)`\n\nResolve a DNS name to a Dat key.\n\n  - `url` is a Dat URL like `dat://dat.foundation`\n  - `key` will be the Dat key that you can pass to `hyperdrive`\n\n### `const {publicKey, secretKey} = await getIdentity()`\n\nThis gives you the public / private keypair used for the Noise protocol encryption when connecting to peers.\nYou can use this to identify peers in the network using `peer.remotePublicKey`\n\n### `const secret = await deriveSecret(namespace, name)`\n\nDerives a secret key based on the SDK's master key.\n`namespace` can be used to namespace different applications, and `name` is the name of the key you want.\nThis can be used as a seed for generating secure private keys without needing to store an extra key on disk.\n\n### `const archive = Hyperdrive(keyOrName, opts)`\n\nThis initializes a Hyperdrive (aka a Dat archive), the SDK will begin finding peers for it and will de-duplicate calls to initializing the same archive more than once.\n\n- `keyOrName`: This **must** be provided. It's either a Dat URL / key or a string identifying the name. If you want to have a writable archive, you can use the name to generate one and use the name later to get the same archive back without having to save the key somewhere.\n- `opts`: These are the options for configuring the hyperdrive.\n  - `sparse: true`: Whether the history should be loaded on the fly instead of replicating the full history\n  - `persist: true`: Whether the data should be persisted to storage. Set to false to create in-memory archives\n  - `secretKey`: A secret key for granting write access. This can be useful when restoring backups.\n\t- `discoveryKey`: Optionally specify which discovery key you'd like to use for finding peers for this archive.\n\t- `lookup: true`: Specify whether you wish to lookup peers for this archive. Set `false` along with `announce` to avoid advertising\n\t- `announce: true`: Specify whether you wish to advertise yourself as having the archive.\n\nThe rest of the Hyperdrive docs were taken from the [Hyperdrive README](https://github.com/mafintosh/hyperdrive/blob/v9/README.md). Note that we're wrapping over the APIs with [Hyperdrive-Promise](https://github.com/geut/hyperdrive-promise) so any callback methods can be `await`ed instead.\n\n#### `archive.version`\n\nGet the current version of the archive (incrementing number).\n\n#### `archive.key`\n\nThe public key identifying the archive.\n\n#### `archive.discoveryKey`\n\nA key derived from the public key that can be used to discovery other peers sharing this archive.\n\n#### `archive.writable`\n\nA boolean indicating whether the archive is writable.\n\n#### `archive.on('ready')`\n\nEmitted when the archive is fully ready and all properties has been populated.\n\n#### `archive.on('update')`\n\nEmitted when the archive has got a new change.\n\n#### `archive.on('error', err)`\n\nEmitted when a critical error during load happened.\n\n#### `archive.on('close')`\n\nEmitted when the archive has been closed\n\n#### `archive.on('peer-add', peer)`\n\nEmitted when a new peer has started replicating wiht the archive.\n\n#### `archive.on('peer-remove', peer)`\n\nEmitted when a peer has stopped replicating wit the archive.\n\n#### `var oldDrive = archive.checkout(version, [opts])`\n\nCheckout a readonly copy of the archive at an old version. Options are used to configure the `oldDrive`:\n\n```js\n{\n  metadataStorageCacheSize: 65536 // how many entries to use in the metadata hypercore's LRU cache\n  contentStorageCacheSize: 65536 // how many entries to use in the content hypercore's LRU cache\n  treeCacheSize: 65536 // how many entries to use in the append-tree's LRU cache\n}\n```\n\n#### `await archive.download([path])`\n\nDownload all files in path of current version.\nIf no path is specified this will download all files.\n\nYou can use this with `.checkout(version)` to download a specific version of the archive.\n\n``` js\narchive.checkout(version).download()\n```\n\n#### `var stream = archive.history([options])`\n\nGet a stream of all changes and their versions from this archive.\n\n#### `var stream = archive.createReadStream(name, [options])`\n\nRead a file out as a stream. Similar to fs.createReadStream.\n\nOptions include:\n\n``` js\n{\n  start: optionalByteOffset, // similar to fs\n  end: optionalInclusiveByteEndOffset, // similar to fs\n  length: optionalByteLength\n}\n```\n\n#### `const data = await archive.readFile(name, [options])`\n\nRead an entire file into memory. Similar to fs.readFile.\n\nOptions can either be an object or a string\n\nOptions include:\n```js\n{\n  encoding: string\n  cached: true|false // default: false\n}\n```\nor a string can be passed as options to simply set the encoding - similar to fs.\n\nIf `cached` is set to `true`, this function returns results only if they have already been downloaded.\n\n#### `var stream = archive.createDiffStream(version, [options])`\n\nDiff this archive with another version. `version` can both be a version number of a checkout instance of the archive. The `data` objects looks like this\n\n``` js\n{\n  type: 'put' | 'del',\n  name: '/some/path/name.txt',\n  value: {\n    // the stat object\n  }\n}\n```\n\n#### `var stream = archive.createWriteStream(name, [options])`\n\nWrite a file as a stream. Similar to fs.createWriteStream.\nIf `options.cached` is set to `true`, this function returns results only if they have already been downloaded.\n\n#### `await archive.writeFile(name, buffer, [options])`\n\nWrite a file from a single buffer. Similar to fs.writeFile.\n\n#### `await archive.unlink(name)`\n\nUnlinks (deletes) a file. Similar to fs.unlink.\n\n#### `await archive.mkdir(name, [options])`\n\nExplictly create an directory. Similar to fs.mkdir\n\n#### `await archive.rmdir(name)`\n\nDelete an empty directory. Similar to fs.rmdir.\n\n#### `const names = await archive.readdir(name, [options])`\n\nLists a directory. Similar to fs.readdir.\n\nOptions include:\n\n``` js\n{\n    cached: true|false, // default: false\n}\n```\n\nIf `cached` is set to `true`, this function returns results from the local version of the archive’s append-tree. Default behavior is to fetch the latest remote version of the archive before returning list of directories.\n\n#### `const stat = await archive.stat(name, [options])`\n\nStat an entry. Similar to fs.stat. Sample output:\n\n```\nStat {\n  dev: 0,\n  nlink: 1,\n  rdev: 0,\n  blksize: 0,\n  ino: 0,\n  mode: 16877,\n  uid: 0,\n  gid: 0,\n  size: 0,\n  offset: 0,\n  blocks: 0,\n  atime: 2017-04-10T18:59:00.147Z,\n  mtime: 2017-04-10T18:59:00.147Z,\n  ctime: 2017-04-10T18:59:00.147Z,\n  linkname: undefined }\n```\n\nThe output object includes methods similar to fs.stat:\n\n``` js\nvar stat = archive.stat('/hello.txt')\nstat.isDirectory()\nstat.isFile()\n```\n\nOptions include:\n```js\n{\n  cached: true|false // default: false,\n  wait: true|false // default: true\n}\n```\n\nIf `cached` is set to `true`, this function returns results only if they have already been downloaded.\n\nIf `wait` is set to `true`, this function will wait for data to be downloaded. If false, will return an error.\n\n#### `await archive.lstat(name, [options])`\n\nStat an entry but do not follow symlinks. Similar to fs.lstat.\n\nOptions include:\n```js\n{\n  cached: true|false // default: false,\n  wait: true|false // default: true\n}\n```\n\nIf `cached` is set to `true`, this function returns results only if they have already been downloaded.\n\nIf `wait` is set to `true`, this function will wait for data to be downloaded. If false, will return an error.\n\n#### `await archive.access(name, [options])`\n\nSimilar to fs.access.\n\nOptions include:\n```js\n{\n  cached: true|false // default: false,\n  wait: true|false // default: true\n}\n```\n\nIf `cached` is set to `true`, this function returns results only if they have already been downloaded.\n\nIf `wait` is set to `true`, this function will wait for data to be downloaded. If false, will return an error.\n\n#### `const fd = await archive.open(name, flags, [mode])`\n\nOpen a file and get a file descriptor back. Similar to fs.open.\n\nNote that currently only read mode is supported in this API.\n\n#### `await archive.read(fd, buf, offset, len, position)`\n\nRead from a file descriptor into a buffer. Similar to fs.read.\n\n#### `await archive.close(fd)`\n\nClose a file. Similar to fs.close.\n\n#### `await archive.close()`\n\nCloses all open resources used by the archive.\nThe archive should no longer be used after calling this.\n\n#### `await archive.destroyData()`\n\nCloses all resources used by the archive, and destroys its data from storage.\nThe archive should no longer be used after calling this.\n\n### `const feed = Hypercore(keyOrName, opts)`\n\nInitializes a Hypercore (aka Feed) and begins replicating it.\n\n- `keyOrName`: This **must** be provided. It's either a Dat URL / key or a string identifying the name of the feed. If you want to have a writable feed, you can use the name to generate one and use the name later to get the same feed back without having to save the key somewhere.\n- `opts`: The options for configuring this feed\n  - `sparse: true`: Whether the history should be loaded on the fly instead of replicating the full history\n  - `persist: true`: Whether the data should be persisted to storage. Set to false to create in-memory feeds\n  - `valueEncoding: 'json' | 'utf-8' | 'binary'`: The encoding to use for the data stored in the hypercore. Use JSON to store / retrieve objects.\n  - `secretKey`: The secret key to use for the feed. Useful for restoring from backups.\n\t- `discoveryKey`: Optionally specify which discovery key you'd like to use for finding peers for this feed.\n\t- `lookup: true`: Specify whether you wish to lookup peers for this feed. Set to `false` along with `announce` to avoid advertising.\n\t- `announce: true`: Specify whether you wish to advertise yourself as having the feed.\n\n#### `const seq = await feed.append(data)`\n\nAppend a block of data to the feed.\n\nCallback is called with `(err, seq)` when all data has been written at the returned `seq` or an error occurred.\n\n#### `const data = await feed.get(index, [options])`\n\nGet a block of data.\nIf the data is not available locally this method will prioritize and wait for the data to be downloaded before calling the callback.\n\nOptions include\n\n``` js\n{\n  wait: true, // wait for index to be downloaded\n  timeout: 0, // wait at max some milliseconds (0 means no timeout)\n  valueEncoding: 'json' | 'utf-8' | 'binary' // defaults to the feed's valueEncoding\n}\n```\n\nCallback is called with `(err, data)`\n\n#### `const results = await feed.getBatch(start, end, [options])`\n\nGet a range of blocks efficiently. Options include\n\n``` js\n{\n  wait: sameAsAbove,\n  timeout: sameAsAbove,\n  valueEncoding: sameAsAbove\n}\n```\n\n#### `const data = await feed.head([options])`\n\nGet the block of data at the tip of the feed. This will be the most recently\nappended block.\n\nAccepts the same `options` as `feed.get()`.\n\n#### `await feed.download([range])`\n\nDownload a range of data. Callback is called when all data has been downloaded.\nA range can have the following properties:\n\n``` js\n{\n  start: startIndex,\n  end: nonInclusiveEndIndex,\n  linear: false // download range linearly and not randomly\n}\n```\n\nIf you do not mark a range the entire feed will be marked for download.\n\nIf you have not enabled sparse mode (`sparse: true` in the feed constructor) then the entire\nfeed will be marked for download for you when the feed is created.\n\n#### `await feed.undownload(range)`\n\nCancel a previous download request.\n\n#### `const signature = await feed.signature([index])`\n\nGet a signature proving the correctness of the block at index, or the whole stream.\n\nCallback is called with `(err, signature)`.\nThe signature has the following properties:\n``` js\n{\n  index: lastSignedBlock,\n  signature: Buffer\n}\n```\n\n#### `const success = await feed.verify(index, signature)`\n\nVerify a signature is correct for the data up to index, which must be the last signed\nblock associated with the signature.\n\nCallback is called with `(err, success)` where success is true only if the signature is\ncorrect.\n\n#### `const roots = await feed.rootHashes(index)`\n\nRetrieve the root *hashes* for given `index`.\n\nCallback is called with `(err, roots)`; `roots` is an *Array* of *Node* objects:\n```\nNode {\n  index: location in the merkle tree of this root\n  size: total bytes in children of this root\n  hash: hash of the children of this root (32-byte buffer)\n}\n```\n\n\n#### `var number = feed.downloaded([start], [end])`\n\nReturns total number of downloaded blocks within range.\nIf `end` is not specified it will default to the total number of blocks.\nIf `start` is not specified it will default to 0.\n\n#### `var bool = feed.has(index)`\n\nReturn true if a data block is available locally.\nFalse otherwise.\n\n#### `var bool = feed.has(start, end)`\nReturn true if all data blocks within a range are available locally.\nFalse otherwise.\n\n#### `await feed.clear(start, [end])`\n\nClear a range of data from the local cache.\nWill clear the data from the bitfield and make a call to the underlying storage provider to delete the byte range the range occupies.\n\n`end` defaults to `start + 1`.\n\n#### `feed.seek(byteOffset, callback)`\n\nSeek to a byte offset.\n\nCalls the callback with `(err, index, relativeOffset)`, where `index` is the data block the byteOffset is contained in and `relativeOffset` is\nthe relative byte offset in the data block.\n\n#### `await feed.update([minLength])`\n\nWait for the feed to contain at least `minLength` elements.\nIf you do not provide `minLength` it will be set to current length + 1.\n\nDoes not download any data from peers except for a proof of the new feed length.\n\n``` js\nconsole.log('length is', feed.length)\nfeed.update(function () {\n  console.log('length has increased', feed.length)\n})\n```\n\n#### `var stream = feed.createReadStream([options])`\n\nCreate a readable stream of data.\n\nOptions include:\n\n``` js\n{\n  start: 0, // read from this index\n  end: feed.length, // read until this index\n  snapshot: true, // if set to false it will update `end` to `feed.length` on every read\n  tail: false, // sets `start` to `feed.length`\n  live: false, // set to true to keep reading forever\n  timeout: 0, // timeout for each data event (0 means no timeout)\n  wait: true // wait for data to be downloaded\n}\n```\n\n#### `var stream = feed.createWriteStream()`\n\nCreate a writable stream.\n\n#### `await feed.close()`\n\nFully close this feed.\n\nCalls the callback with `(err)` when all storage has been closed.\n\n#### `await feed.destroyData()`\n\nCloses the feed and deletes all of it's data from storage.\n\n#### `const {valid, invalid} = await feed.audit()`\n\nAudit all data in the feed. Will check that all current data stored\nmatches the hashes in the merkle tree and clear the bitfield if not.\n\nWhen done a report is passed to the callback that looks like this:\n\n```js\n{\n  valid: 10, // how many data blocks matches the hashes\n  invalid: 0, // how many did not\n}\n```\n\nIf a block does not match the hash it is cleared from the data bitfield.\n\n#### `const extension = feed.registerExtension(name, handlers)`\n\nListens on extension messages of type `name` on the feeds replication channels.\n\n- `handlers.encoding`: The encoding to use for messages. `json`, `binary`, 'utf8'\n- `handlers.onmessage(message, peer)`: Function to invoke when a peer sends you a message for this extension type.\n- `handlers.onerror(err, peer)`: Function to invoke when a peer has sent you a mis-coded message on this extension.\n\nYou can respond to messages with `extension.send(message, peer)`.\n\n#### `feed.writable`\n\nCan we append to this feed?\n\nPopulated after `ready` has been emitted. Will be `false` before the event.\n\n#### `feed.readable`\n\nCan we read from this feed? After closing a feed this will be false.\n\nPopulated after `ready` has been emitted. Will be `false` before the event.\n\n#### `feed.key`\n\nBuffer containing the public key identifying this feed.\n\nPopulated after `ready` has been emitted. Will be `null` before the event.\n\n#### `feed.discoveryKey`\n\nBuffer containing a key derived from the feed.key.\nIn contrast to `feed.key` this key does not allow you to verify the data but can be used to announce or look for peers that are sharing the same feed, without leaking the feed key.\n\nPopulated after `ready` has been emitted. Will be `null` before the event.\n\n#### `feed.length`\n\nHow many blocks of data are available on this feed?\n\nPopulated after `ready` has been emitted. Will be `0` before the event.\n\n#### `feed.byteLength`\n\nHow much data is available on this feed in bytes?\n\nPopulated after `ready` has been emitted. Will be `0` before the event.\n\n#### `feed.stats`\n\nReturn per-peer and total upload/download counts.\n\nThe returned object is of the form:\n```js\n{\n  totals: {\n    uploadedBytes: 100,\n    uploadedBlocks: 1,\n    downloadedBytes: 0,\n    downloadedBlocks: 0\n  },\n  peers: [\n    {\n      uploadedBytes: 100,\n      uploadedBlocks: 1,\n      downloadedBytes: 0,\n      downloadedBlocks: 0\n    },\n    ...\n  ]\n}\n```\n\nStats will be collected by default, but this can be disabled by setting `opts.stats` to false.\n\n#### `feed.on('ready')`\n\nEmitted when the feed is ready and all properties have been populated.\n\n#### `feed.on('error', err)`\n\nEmitted when the feed experiences a critical error.\n\n#### `feed.on('download', index, data)`\n\nEmitted when a data block has been downloaded.\n\n#### `feed.on('upload', index, data)`\n\nEmitted when a data block is uploaded.\n\n#### `feed.on('append')`\n\nEmitted when the feed has been appended to (i.e. has a new length / byteLength)\n\n#### `feed.on('sync')`\n\nEmitted every time ALL data from `0` to `feed.length` has been downloaded.\n\n#### `feed.on('close')`\n\nEmitted when the feed has been fully closed\n\n#### `feed.on('peer-add', peer)`\n\nEmitted when a new peer has started replicating with the feed.\n\n#### `feed.on('peer-remove', peer)`\n\nEmitted when a peer has stopped replicating with the feed.\n\n\n---\n\n[Dat Project]: https://dat.foundation\n","browser":{"dat-dns":"./dns-web.js","hyperswarm":"hyperswarm-web","sodium-native":"@geut/sodium-javascript-plus","sodium-universal":"@geut/sodium-javascript-plus"},"gitHead":"f47c4b983fcf4c639ca92418069b5b9f6081d15a","license":"MIT","scripts":{"test":"node test","build":"cross-env BABEL_DISABLE_CACHE=1 browserify index.js > dat-sdk-bundle.js","build-test":"cross-env BABEL_DISABLE_CACHE=1 browserify -t [ babelify --global ] -d test.js > test-bundle.js"},"_npmUser":{"name":"rangermauve","email":"rangermauve@hotmail.com"},"homepage":"https://github.com/datproject/sdk#readme","keywords":["dat","sdk","hyperdrive","hypercore","p2p"],"browserify":{"transform":[["babelify",{"global":true}]]},"repository":{"url":"git+https://github.com/datproject/sdk.git","type":"git"},"_npmVersion":"6.14.4","description":"The official Dat SDK","directories":{},"maintainers":[{"name":"rangermauve","email":"rangermauve@hotmail.com"}],"_nodeVersion":"12.16.2","dependencies":{"global":"^4.4.0","dat-dns":"^4.0.0","corestore":"^5.1.1","hex-to-32":"^2.0.0","hypercore":"github:rangermauve/hypercore#destroy-rename","url-parse":"^1.4.7","hyperdrive":"github:rangermauve/hyperdrive#destroy","dat-encoding":"^5.0.1","concat-stream":"^2.0.0","hyperswarm-web":"^1.0.2","dom-event-target":"^1.0.0","hypercore-crypto":"^1.0.0","universal-prompt":"^1.0.0","node-localstorage":"^2.1.5","hypercore-protocol":"^7.10.0","random-access-memory":"^3.1.1","universal-localstorage":"^1.0.2","@geut/hypercore-promise":"^1.1.0","@geut/hyperdrive-promise":"^3.0.0","random-access-application":"^1.0.0","corestore-swarm-networking":"^5.1.0","@geut/sodium-javascript-plus":"0.0.4"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"tmp":"^0.1.0","tape":"^4.10.2","util":"^0.12.2","babelify":"^10.0.0","cross-env":"^7.0.2","browserify":"^16.2.3","@babel/core":"^7.9.0","random-access-file":"^2.1.3","babel-plugin-module-resolver":"^4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/dat-sdk_2.0.0-7_1588959985939_0.20806815124324296","host":"s3://npm-registry-packages"},"_id":"dat-sdk@2.0.0-7","version":"2.0.0-7"}