{"id":13482124,"url":"https://github.com/webtorrent/torrent-piece","last_synced_at":"2025-03-27T12:32:30.939Z","repository":{"id":36730797,"uuid":"41037379","full_name":"webtorrent/torrent-piece","owner":"webtorrent","description":"Torrent piece abstraction","archived":false,"fork":false,"pushed_at":"2024-10-26T16:31:36.000Z","size":896,"stargazers_count":23,"open_issues_count":9,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-30T00:27:31.328Z","etag":null,"topics":["bittorrent","browser","javascript","nodejs","piece","torrent","webtorrent"],"latest_commit_sha":null,"homepage":"https://webtorrent.io","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"jiafeng5513/Evision","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webtorrent.png","metadata":{"funding":{"github":["webtorrent","feross"]},"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-08-19T13:54:52.000Z","updated_at":"2024-10-26T16:31:39.000Z","dependencies_parsed_at":"2023-10-13T11:35:51.077Z","dependency_job_id":"1ccfb52a-c6f1-4f47-8d8e-98392d4a6c39","html_url":"https://github.com/webtorrent/torrent-piece","commit_stats":{"total_commits":53,"total_committers":11,"mean_commits":4.818181818181818,"dds":0.4716981132075472,"last_synced_commit":"d075805d24816047add03c70f412fceeb5e699eb"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webtorrent%2Ftorrent-piece","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webtorrent%2Ftorrent-piece/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webtorrent%2Ftorrent-piece/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webtorrent%2Ftorrent-piece/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webtorrent","download_url":"https://codeload.github.com/webtorrent/torrent-piece/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245845345,"owners_count":20681889,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bittorrent","browser","javascript","nodejs","piece","torrent","webtorrent"],"created_at":"2024-07-31T17:00:59.220Z","updated_at":"2025-03-27T12:32:30.494Z","avatar_url":"https://github.com/webtorrent.png","language":"JavaScript","funding_links":["https://github.com/sponsors/webtorrent","https://github.com/sponsors/feross"],"categories":["Modules"],"sub_categories":[],"readme":"# torrent-piece [![ci][ci-image]][ci-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]\n\n[ci-image]: https://img.shields.io/github/workflow/status/webtorrent/torrent-piece/ci/master\n[ci-url]: https://github.com/webtorrent/torrent-piece/actions\n[npm-image]: https://img.shields.io/npm/v/torrent-piece.svg\n[npm-url]: https://npmjs.org/package/torrent-piece\n[downloads-image]: https://img.shields.io/npm/dm/torrent-piece.svg\n[downloads-url]: https://npmjs.org/package/torrent-piece\n[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg\n[standard-url]: https://standardjs.com\n\n### Torrent piece abstraction\n\n[![Sauce Test Status](https://saucelabs.com/browser-matrix/torrent-piece.svg)](https://saucelabs.com/u/torrent-piece)\n\nAlso works in the browser with [browserify](http://browserify.org/)! This module is used by [WebTorrent](http://webtorrent.io) and [torrent-stream](https://npmjs.com/package/torrent-stream).\n\n## install\n\n```\nnpm install torrent-piece\n```\n\n## usage\n\n```js\nimport Piece from 'torrent-piece'\n\nPiece.BLOCK_LENGTH // 16384\n\nconst pieceLength = Piece.BLOCK_LENGTH * 5\nconst piece = new Piece(pieceLength)\npiece.missing // 81920\n\npiece.reserve() // 0\npiece.set(0, someBuffer0)\n\npiece.reserve() // 1\npiece.reserve() // 2\npiece.reserve() // 3\n\npiece.set(1, someBuffer1)\npiece.set(2, someBuffer2)\npiece.set(3, someBuffer3)\n\npiece.reserve() // 4\npiece.cancel(4) // cancel the reservation of a chunk\n\npiece.reserve() // 4 (given out again)\npiece.set(4, someBuffer4)\n\n// handy functions\npiece.chunkLength(0) // 16384\npiece.chunkOffset(0) // 0\n\n// eventually, when no more chunks left...\n\npiece.reserve() // -1 (signal that all chunks are reserved)\npiece.missing // 0\n\nconst pieceBuffer = piece.flush()\nconsole.log(pieceBuffer)\n```\n\n## license\n\nMIT. Copyright (c) [Feross Aboukhadijeh](https://feross.org) and [WebTorrent, LLC](https://webtorrent.io).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebtorrent%2Ftorrent-piece","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebtorrent%2Ftorrent-piece","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebtorrent%2Ftorrent-piece/lists"}