{"id":13482118,"url":"https://github.com/fent/node-torrent","last_synced_at":"2025-05-06T16:42:50.312Z","repository":{"id":514521,"uuid":"2192549","full_name":"fent/node-torrent","owner":"fent","description":"Torrent reader, writer, and hash checker for node.","archived":false,"fork":false,"pushed_at":"2024-08-27T01:00:10.000Z","size":413,"stargazers_count":196,"open_issues_count":4,"forks_count":36,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-05-01T06:46:18.989Z","etag":null,"topics":["hashcheck","node","torrent"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fent.png","metadata":{"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":"2011-08-11T17:25:35.000Z","updated_at":"2025-04-08T18:48:37.000Z","dependencies_parsed_at":"2024-10-30T15:42:37.846Z","dependency_job_id":null,"html_url":"https://github.com/fent/node-torrent","commit_stats":{"total_commits":181,"total_committers":17,"mean_commits":"10.647058823529411","dds":"0.18232044198895025","last_synced_commit":"a527383f7fca25ec01f0dc1134d8d7ca3907d584"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fent%2Fnode-torrent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fent%2Fnode-torrent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fent%2Fnode-torrent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fent%2Fnode-torrent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fent","download_url":"https://codeload.github.com/fent/node-torrent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252722588,"owners_count":21794081,"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":["hashcheck","node","torrent"],"created_at":"2024-07-31T17:00:59.144Z","updated_at":"2025-05-06T16:42:50.287Z","avatar_url":"https://github.com/fent.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Modules","node"],"sub_categories":[],"readme":"# node-torrent\n\nRead, make, and hash check torrents with node.js!\n\n[![Build Status](https://secure.travis-ci.org/fent/node-torrent.svg)](http://travis-ci.org/fent/node-torrent)\n![Depfu](https://img.shields.io/depfu/fent/node-torrent)\n[![codecov](https://codecov.io/gh/fent/node-torrent/branch/master/graph/badge.svg)](https://codecov.io/gh/fent/node-torrent)\n\n# Usage\n\n## Read a torrent\n\n```javascript\nconst nt = require('nt');\n\nnt.read('path/to/file.torrent', (err, torrent) =\u003e {\n  if (err) throw err;\n  console.log('Info hash:', torrent.infoHash());\n});\n```\n\n## Make a torrent\n\n```javascript\nlet rs = nt.make('http://myannounce.net/url', __dirname + '/files');\nrs.pipe(fs.createWriteStream('mytorrent.torrent'));\n\n// callback style\nnt.makeWrite('outputfile', 'http://announce.me', __dirname + '/files',\n  ['somefile.ext', 'another.one', 'inside/afolder.mkv', 'afolder'],\n  (err, torrent) =\u003e {\n    if (err) throw err;\n    console.log('Finished writing torrent!');\n  });\n```\n\n## Hash check a torrent\n\n```js\nlet hasher = torrent.hashCheck(file);\n\nlet p;\nhasher.on('match', (i, hash, percent) =\u003e {\n  p = percent;\n});\n\nhasher.on('end', () =\u003e {\n  console.log('Hash Check:', p + '%', 'matched');\n});\n```\n\n\n# API\n\n### read(file, callback(Error, Torrent))\n\nReads a local file, or a readable stream. Returns readable stream.\n\nAn error can be returned if the torrent is formatted incorrectly. Does not check if the dictonaries are listed alphabetically. Refer to the [BitTorrent Specification](http://wiki.theory.org/BitTorrentSpecification) for more info on torrent metainfo.\n\n### make(announceURL, dir, [files], [options], [callback(Error, Torrent)])\n\nMakes a new torrent. `dir` is root directory of the torrent. The `files` array will relatively read files from there. If files is omitted, it implicitly adds all of the files in `dir` to the torrent, including those in subdirectories. `options` can have the following:\n\n* `announceList` - An array of arrays of additional announce URLs.\n* `comment`\n* `name` - Can be used only in multi file mode. If not given, defaults to name of directory.\n* `pieceLength` - How to break up the pieces. Must be an integer `n` that says piece length will be `2^n`. Default is 256KB, or 2^18.\n* `private` - Set true if this is a private torrent.\n* `moreInfo` - These go into the `info` dictionary of the torrent. Useful if you want to make a torrent have a unique info hash from a certain tracker.\n* `maxFiles` - Max files to open during piece hashing. Defaults to 250.\n\n`callback` is called with a possible `Error`, and a `Torrent` object when hashing is finished.\n\n`make` returns a Hasher object that emits raw bencoded `data` events.\n\n### makeWrite(output, annlounce, dir, [files], [options], [callback(Error, Torrent)])\n\nA shortcut that pumps the returned readable stream from `make` into a writable stream that points to the file `output`. Returns a Hasher object.\n\n\n## Torrent\n\nThe `read` and `make` functions all call their callback with a Torrent object.\n\n### Torrent#metadata\n\nContains metadata of the torrent. Example:\n\n```js\n{\n  announce: 'udp://tracker.publicbt.com:80',\n  'announce-list': [\n    [ 'udp://tracker.publicbt.com:80' ],\n    [ 'udp://tracker.ccc.de:80' ],\n    [ 'udp://tracker.openbittorrent.com:80' ],\n    [ 'http://tracker.thepiratebay.org/announce' ]\n  ],\n  comment: 'Torrent downloaded from http://thepiratebay.org',\n  'creation date': 1303979726,\n  info: { length: 718583808,\n    name: 'ubuntu-11.04-desktop-i386.iso',\n    'piece length': 524288,\n    pieces: \u003cBuffer e5 7a ...\u003e\n  }\n}\n```\n\n### Torrent#infoHash()\n\nGet a torrent's info hash.\n\n### Torrent#createReadStream()\n\nCreates a ReadableStream that emits raw bencoded data for this torrent. Returns the readable stream.\n\n### Torrent#createWriteStream(filepath)\n\nShortcut that pipes the stream from `Torrent#createReadStream()` to a writable file stream. Returns the writable stream.\n\n### Torrent#hashCheck(dir, [options])\n\nHash checks torrent against files in `dir`. Returns a Hasher object. `options` hash can have `maxFiles` to open during hashing. Defaults to `250`. Returns a Hasher object.\n\n\n## Hasher\n\nA Hasher object is returned when a torrent is created with `make` and when `Torrent#hashCheck` is called. It inherits from ReadableStream.\n\n### Hasher#pause()\n\nPause hash checking.\n\n### Hasher#resume()\n\nResumes hash checking.\n\n### Hasher#toggle()\n\nContinues hashing if paused or pauses if not.\n\n### Hasher#destroy()\n\nStops hashing completely. Closes file descriptors and does not emit any more events.\n\n### Event: 'ready'\n\nFinished examining files to be hashed and ready to start hashing their contents.\n\n### Event: 'data'\n* `Buffer` - data\n\nEmits raw bencoded torrent data only when hasher is returned from the `make` function.\n\n### 'progress'\n* `number` - percent\n* `number` - speed\n* `number` - avgSpeed\n\nEmits the progress calculated by amount of bytes read from files. `speed` and `avgSpeed` are in bytes.\n\n### 'hash'\n* `number` - index\n* `string` - hash\n* `string` - file\n* `number` - position\n* `number` - length\n\nEmitted when a piece is hashed along with hash position and source.\n\n### 'match'\n* `number` - index\n* `string` - hash\n* `number` - percentMatched\n* `string` - file\n* `number` - position\n* `number` - length\n\nEmitted when a piece matches with its `index`, the piece, and the percentage of pieces matched so far.\n\n### 'matcherror'\n* `number` - index\n* `string` - file\n* `number` - position\n* `number` - length\n\nEmitted when a piece does not match.\n\n### 'error'\n* `Error` - err\n\nError hash checking.\n\n### 'end'\n\nHash checking is finished.\n\n\n# Install\n\n    npm install nt\n\n\n# Tests\nTests are written with [vows](http://vowsjs.org/)\n\n```bash\nnpm test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffent%2Fnode-torrent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffent%2Fnode-torrent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffent%2Fnode-torrent/lists"}