{"_id":"hypercore-seekable-iterator","_rev":"2-dea8578b725ad22c22abf44569b823bc","name":"hypercore-seekable-iterator","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"hypercore-seekable-iterator","version":"1.0.0","description":"An async iterator for Hypercores that supports seek","main":"index.js","scripts":{"test":"standard && tape test/*.js"},"repository":{"type":"git","url":"git+https://github.com/andrewosh/hypercore-seekable-iterator.git"},"keywords":["hypercore","seek","iterator"],"author":{"name":"Andrew Osheroff","email":"andrewosh@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/andrewosh/hypercore-seekable-iterator/issues"},"homepage":"https://github.com/andrewosh/hypercore-seekable-iterator#readme","devDependencies":{"hypercore":"^9.6.0","random-access-memory":"^3.1.1","standard":"^16.0.3","tape":"^5.0.1"},"dependencies":{"abort-controller":"^3.0.0"},"gitHead":"e867370fc57db1b5147c5f13f248dca01b30d4d1","_id":"hypercore-seekable-iterator@1.0.0","_nodeVersion":"14.15.0","_npmVersion":"6.14.8","dist":{"integrity":"sha512-vwgw22rYVSAHtwSwsLN2LEB3EKQWuMsmY9Zd4gzlx8JP5jnV7v+B04Cl+LT45x6/Sl15Q77VttB5l3ijgUc7rA==","shasum":"cccd95306e70aa834da98e6104a2b448c05d4165","tarball":"https://registry.npmjs.org/hypercore-seekable-iterator/-/hypercore-seekable-iterator-1.0.0.tgz","fileCount":4,"unpackedSize":10871,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfy+l+CRA9TVsSAnZWagAAK4YP/RGkHN04NFmwdLAFSHIp\nCtZvijcSfyVIW+44nsx0JuymhETEpSV/5pzgGcvnYbOPmLEZ08jj+uFfkFGU\nBt1UrYVALdSM9JLQi21ItVRGfNuMFkM+HUwGk8mcnHbxjyaLjNjNj4U8+RWz\nW5Wlj9wLy/oyAvQcp43jPtjrYDTLOCOSnHZ/ENHPesM4EJcna5oPp+pvz831\nptnscTYz8SUxQ4jUunRTUOamrocEUgiI1C4xTdITrer5nUCrN6C9c//Tf4IF\n8KU6K9paTw1+u52i2L2u8hVvWYFoHd1ORsnpCpLABWMqlwdybFxG0fvuX12a\nvG43YdnDprm2ZhjY0b1K43jd1r8cevIOxx4+3IK42cMATbu78itrAFwPiXMb\n6GC/X6XSL9GyBTZfBZyLUFeyfYHQY+cgwMZDIH+buMbIVXz42RQUuWu7i+ND\nOt3wGXE++5UFhPPDxA2eCvTYJObObqlHUeRuKAAGZna0Q2J1//wTXRA4vE1f\nhRtpO5+jjYLbn7rKw712VBP9zW6ArjhqcRHbflJcbWF3XCjM25rqxjWBax+F\nQPCxmYgl7GRsoOrtERfDMVw8hitlvsPnfM7sDVg5Q3KWxIwJpnP76yNFryvK\nLS15OcOWJSbseYdM3wopRqg91+a/AcSSCtrXhLzjzHpUmOPpBqJsiuqzn8TS\n/o1/\r\n=b3d9\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDkiAhr8fcBjra33BhYLQcAPRKtmwB4I0y6W+TqMpGEAAIhAJgdvOvHiyS0cpjya/jAvGRirH/CyhapjZDe5oTQ3TxK"}]},"_npmUser":{"name":"andrewosh","email":"andrewosh@gmail.com"},"directories":{},"maintainers":[{"name":"andrewosh","email":"andrewosh@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hypercore-seekable-iterator_1.0.0_1607199101690_0.5866661593815994"},"_hasShrinkwrap":false},"1.1.0":{"name":"hypercore-seekable-iterator","version":"1.1.0","description":"An async iterator for Hypercores that supports seek","main":"index.js","scripts":{"test":"standard && tape test/*.js"},"repository":{"type":"git","url":"git+https://github.com/andrewosh/hypercore-seekable-iterator.git"},"keywords":["hypercore","seek","iterator"],"author":{"name":"Andrew Osheroff","email":"andrewosh@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/andrewosh/hypercore-seekable-iterator/issues"},"homepage":"https://github.com/andrewosh/hypercore-seekable-iterator#readme","devDependencies":{"hypercore":"^9.6.0","random-access-memory":"^3.1.1","standard":"^16.0.3","tape":"^5.0.1"},"dependencies":{"abort-controller":"^3.0.0"},"gitHead":"b39b78935043912d6cf18df17d3d58cea8bfa328","_id":"hypercore-seekable-iterator@1.1.0","_nodeVersion":"14.15.0","_npmVersion":"6.14.8","dist":{"integrity":"sha512-41kh5wbXEcFhHLLV+p9K2Nm/qH87xaa2hm2AvGzZAqjcoigYttGGYH0HVy0fyeCTzkzcojD3M/RO2v/ah0JcuA==","shasum":"f0143e57ef4b5cd825422a57d4b4b22210b7c66a","tarball":"https://registry.npmjs.org/hypercore-seekable-iterator/-/hypercore-seekable-iterator-1.1.0.tgz","fileCount":4,"unpackedSize":10934,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfy+2hCRA9TVsSAnZWagAArpYP/3d6omYlJ8cF65kuvBCJ\n9+CgrfPBziZsshOgjCWIrME91lsKc1J9se+BXcTdfoMnQukV1G2wNLwQVzox\nQe/sjjqUi1Cxr7FunLCYDtCoyhUP7a4AtEGT5IOne4pBvKrZFXqIH5DjLzCg\nu21uFtlUMs8QLi/tgHvz1rL8VuzJS7ORUxmuYTpPWijuHC/f9BiY4cSzqCIj\nzPSGRta+rr87QreFPL/WBCzebeZB7fAgikkpu6NWBryOWebxxO8344dAYCY+\nhx5p1fCdOSh1j7HPlva4Ux3Be3ZoyvfvwKKpoiO6UgICpuWpNt/oakEIc9bw\nviQRopj6OSseabYIy69zdf5Cyk9DiqTowN11hFw6qJFtCTO+jslDrgQp+sUR\noMdqqvqo9LzwuEqLsaTNyaoWaBCMkmApnvefY8CFm09sSICPFHTfrJY0xSIE\nCcTq+BCDPNatMPGsubauD6DRx6La5upWdJozRUYjTHmg9CbRICYUwL/7Djux\nAJV7OjSGozZ2SG3k3byrQjLFq+5Ci3j+B5zauPVrLTkLdiQjeZrg68bNmCZo\nnbk5PyV1fZ5/9YWwQNIJNtk5kM4Iu+HKHPKYZ0loQq/MFeXCxVgo2Rz9dItr\nHYBqPTsF9g5mEanhkJeYjVS3Qzv/YSzHq7qtcUqhRbCHVeCt6ZysHoipmsY1\ngu5g\r\n=ILUr\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCxuV58Kl6wJYx9Vt/IoKJpAefhgQXAjBQ5jLIw/pLA/AIgP8j+bNPB9WMBO69fC8YJMNrhNXkwh3n8j3l3MZlEHS0="}]},"_npmUser":{"name":"andrewosh","email":"andrewosh@gmail.com"},"directories":{},"maintainers":[{"name":"andrewosh","email":"andrewosh@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hypercore-seekable-iterator_1.1.0_1607200160889_0.3182395517586536"},"_hasShrinkwrap":false}},"time":{"created":"2020-12-05T20:11:41.690Z","1.0.0":"2020-12-05T20:11:41.872Z","modified":"2022-05-05T12:25:38.868Z","1.1.0":"2020-12-05T20:29:21.044Z"},"maintainers":[{"name":"andrewosh","email":"andrewosh@gmail.com"}],"description":"An async iterator for Hypercores that supports seek","homepage":"https://github.com/andrewosh/hypercore-seekable-iterator#readme","keywords":["hypercore","seek","iterator"],"repository":{"type":"git","url":"git+https://github.com/andrewosh/hypercore-seekable-iterator.git"},"author":{"name":"Andrew Osheroff","email":"andrewosh@gmail.com"},"bugs":{"url":"https://github.com/andrewosh/hypercore-seekable-iterator/issues"},"license":"MIT","readme":"# hypercore-seekable-iterator\n\nA seekable AsyncIterator for Hypercores that supports AbortControllers for cancellation, and block prefetching.\n\nBy default, the iterator will linearly prefetch the next 10 blocks each time a chunk is read.\n\n## Installation\n```\nnpm i hypercore-seekable-iterator\n```\n\n## Example\n```js\nconst core = hypercore(ram)\nconst SeekableIterator = require('hypercore-seekable-iterator')\n\n// Assuming the core contains many blocks.\n\nconst ite = new SeekableIterator(core, {\n  // Start reading at byte offset 10 in the Hypercore\n  byteOffset: 10,\n    // Stop reading at position 60\n  byteLength: 50\n})\n\nfor await (const chunk of ite) {\n  // Can seek during iteration.\n  // Seeking is sync, and will happen before the next chunk is yielded.\n  // The seek argument is relative to the initial start position.\n  if (chunk.length === 10) {\n    ite.seek(0)\n  }\n}\n```\n\n## API\n\n#### `const ite = new HypercoreSeekableIterator(core, opts = {})`\nCreate a new iterator.\n\nOptions include:\n```js\n  byteOffset, // The initial byte offset\n  byteLength, // The size of the range to read (defines the end position)\n  startBlock, // (Optimization) If you know which block the start position is in, this speeds up the first read\n  endBlock,   // (Optimization) If you know which block the end position is in, this speeds up the first read,\n  prefetch    // A function of the form (ite, index) => (download range)\n```\n\n#### `await ite.next()`\nYield the next chunk.\n\n#### `ite.seek(pos)`\nSeek to a numeric position relative to the initial starting byte offset (e.g. `ite.seek(0)` will return to the initial position).\n\n### Prefetch\nYou can pass in a custom prefetching function to define how blocks should be downloaded in the background during iteration.\n\nThe default prefetch will always download the next 10 blocks. In the future, this will become adaptive!\n\nA prefetch function returns arguments to Hypercore's `download` method:\n```js\nfunction customPrefetch (ite, index) {\n  return { start: index + 1, end: index + 5, linear: true }\n}\n```\n`ite` is an instance of HypercoreSeekableIterator (you can use this to determine download bounds).\n`index` is the index of the current read.\n\n## License\nMIT\n","readmeFilename":"README.md"}