Giter Site home page Giter Site logo

webtorrent / parse-torrent Goto Github PK

View Code? Open in Web Editor NEW
434.0 434.0 79.0 270 KB

Parse a torrent identifier (magnet uri, .torrent file, info hash)

Home Page: https://webtorrent.io

License: MIT License

JavaScript 100.00%
bittorrent browser javascript magnet-uri nodejs parse torrent webtorrent

parse-torrent's Introduction


WebTorrent
WebTorrent

The streaming torrent client. For node.js and the web.

discord ci npm version npm downloads Standard - JavaScript Style Guide

Sponsored by    Socket - JavaScript open source supply chain security    Wormhole

WebTorrent is a streaming torrent client for node.js and the browser. YEP, THAT'S RIGHT. THE BROWSER. It's written completely in JavaScript – the language of the web – so the same code works in both runtimes.

In node.js, this module is a simple torrent client, using TCP and UDP to talk to other torrent clients.

In the browser, WebTorrent uses WebRTC (data channels) for peer-to-peer transport. It can be used without browser plugins, extensions, or installations. It's Just JavaScript™. Note: WebTorrent does not support UDP/TCP peers in browser.

Simply include the webtorrent.min.js script on your page to start fetching files over WebRTC using the BitTorrent protocol, or import WebTorrent from 'webtorrent' with browserify or webpack. See demo apps and code examples below.

jsdelivr download count

To make BitTorrent work over WebRTC (which is the only P2P transport that works on the web) we made some protocol changes. Therefore, a browser-based WebTorrent client or "web peer" can only connect to other clients that support WebTorrent/WebRTC.

To seed files to web peers, use a client that supports WebTorrent, e.g. WebTorrent Desktop, a desktop client with a familiar UI that can connect to web peers, webtorrent-hybrid, a command line program, or Instant.io, a website. Established torrent clients like Vuze have already added WebTorrent support so they can connect to both normal and web peers. We hope other clients will follow.

Network

Features

  • Torrent client for node.js & the browser (same npm package!)
  • Insanely fast
  • Download multiple torrents simultaneously, efficiently
  • Pure Javascript (no native dependencies)
  • Exposes files as streams
    • Fetches pieces from the network on-demand so seeking is supported (even before torrent is finished)
    • Seamlessly switches between sequential and rarest-first piece selection strategy
  • Supports advanced torrent client features
  • Comprehensive test suite (runs completely offline, so it's reliable and fast)
  • Check all the supported BEPs here

Browser/WebRTC environment features

  • WebRTC data channels for lightweight peer-to-peer communication with no plugins
  • No silos. WebTorrent is a P2P network for the entire web. WebTorrent clients running on one domain can connect to clients on any other domain.
  • Stream video torrents into a <video> tag (webm, mkv, mp4, ogv, mov, etc (AV1, H264, HEVC*, VP8, VP9, AAC, FLAC, MP3, OPUS, Vorbis, etc))
  • Supports Chrome, Firefox, Opera and Safari.

Install

To install WebTorrent for use in node or the browser with import WebTorrent from 'webtorrent', run:

npm install webtorrent

To install a webtorrent command line program, run:

npm install webtorrent-cli -g

To install a WebTorrent desktop application for Mac, Windows, or Linux, see WebTorrent Desktop.

Ways to help

Who is using WebTorrent today?

Lots of folks!

WebTorrent API Documentation

Read the full API Documentation.

Usage

WebTorrent is the first BitTorrent client that works in the browser, using open web standards (no plugins, just HTML5 and WebRTC)! It's easy to get started!

In the browser

Downloading a file is simple:
import WebTorrent from 'webtorrent'

const client = new WebTorrent()
const magnetURI = '...'

client.add(magnetURI, torrent => {
  // Got torrent metadata!
  console.log('Client is downloading:', torrent.infoHash)

  for (const file of torrent.files) {
    document.body.append(file.name)
  }
})
Seeding a file is simple, too:
import dragDrop from 'drag-drop'
import WebTorrent from 'webtorrent'

const client = new WebTorrent()

// When user drops files on the browser, create a new torrent and start seeding it!
dragDrop('body', files => {
  client.seed(files, torrent => {
    console.log('Client is seeding:', torrent.infoHash)
  })
})

There are more examples in docs/get-started.md.

Browserify

WebTorrent works great with browserify, an npm package that lets you use node-style require() to organize your browser code and load modules installed by npm (as seen in the previous examples).

Webpack

WebTorrent also works with webpack, another module bundler. However, webpack requires extra configuration which you can find in the webpack bundle config used by webtorrent.

Or, you can just use the pre-built version via import WebTorrent from 'webtorrent/dist/webtorrent.min.js' and skip the webpack configuration.

Script tag

WebTorrent is also available as a standalone script (webtorrent.min.js) which exposes WebTorrent on the window object, so it can be used with just a script tag:

<script type='module'>
  import WebTorrent from 'webtorrent.min.js'
</script>

The WebTorrent script is also hosted on fast, reliable CDN infrastructure (Cloudflare and MaxCDN) for easy inclusion on your site:

<script type='module'>
  import WebTorrent from 'https://esm.sh/webtorrent'
</script>
Chrome App

If you want to use WebTorrent in a Chrome App, you can include the following script:

<script type='module'>
  import WebTorrent from 'webtorrent.chromeapp.js'
</script>

Be sure to enable the chrome.sockets.udp and chrome.sockets.tcp permissions!

In Node.js

WebTorrent also works in node.js, using the same npm package! It's mad science!

NOTE: To connect to "web peers" (browsers) in addition to normal BitTorrent peers, use webtorrent-hybrid which includes WebRTC support for node.

As a command line app

WebTorrent is also available as a command line app. Here's how to use it:

$ npm install webtorrent-cli -g
$ webtorrent --help

To download a torrent:

$ webtorrent magnet_uri

To stream a torrent to a device like AirPlay or Chromecast, just pass a flag:

$ webtorrent magnet_uri --airplay

There are many supported streaming options:

--airplay               Apple TV
--chromecast            Chromecast
--mplayer               MPlayer
--mpv                   MPV
--omx [jack]            omx [default: hdmi]
--vlc                   VLC
--xbmc                  XBMC
--stdout                standard out [implies --quiet]

In addition to magnet uris, WebTorrent supports many ways to specify a torrent.

Talks about WebTorrent

Modules

Most of the active development is happening inside of small npm packages which are used by WebTorrent.

The Node Way™

"When applications are done well, they are just the really application-specific, brackish residue that can't be so easily abstracted away. All the nice, reusable components sublimate away onto github and npm where everybody can collaborate to advance the commons." — substack from "how I write modules"

node.js is shiny

Modules

These are the main modules that make up WebTorrent:

module tests version description
webtorrent torrent client (this module)
bittorrent-dht distributed hash table client
bittorrent-peerid identify client name/version
bittorrent-protocol bittorrent protocol stream
bittorrent-tracker bittorrent tracker server/client
bittorrent-lsd bittorrent local service discovery
create-torrent create .torrent files
magnet-uri parse magnet uris
parse-torrent parse torrent identifiers
torrent-discovery find peers via dht, tracker, and lsd
ut_metadata metadata for magnet uris (protocol extension)
ut_pex peer discovery (protocol extension)

Enable debug logs

In node, enable debug logs by setting the DEBUG environment variable to the name of the module you want to debug (e.g. bittorrent-protocol, or * to print all logs).

DEBUG=* webtorrent

In the browser, enable debug logs by running this in the developer console:

localStorage.setItem('debug', '*')

Disable by running this:

localStorage.removeItem('debug')

License

MIT. Copyright (c) Feross Aboukhadijeh and WebTorrent, LLC.

parse-torrent's People

Contributors

alxhotel avatar astro avatar diegorbaquero avatar feross avatar greenkeeper[bot] avatar greenkeeperio-bot avatar gridexx avatar gruns avatar jaruba avatar kayleepop avatar keizerdev avatar leask avatar leoherzog avatar linusu avatar renovate-bot avatar renovate[bot] avatar semantic-release-bot avatar sonicdoe avatar thaunknown avatar transitive-bullshit avatar xiaomingplus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

parse-torrent's Issues

Unify "announce" and "announceList" keys

Having two largely similar keys is annoying. They have to be kept in sync when manually modifying the list of trackers, which is done frequently in tests, or even here in webtorrent.

Zero-length file path segments disappear when they get path.joined

What version of this package are you using?

9.1.3

What operating system, Node.js, and npm version?

Mac, Node 10, npm 7.6.0

The Situation

I have two torrents with slightly different file structures.
They both are multi-file torrents.

Torrent 1:

{
  info: {
    files: [
      {
        path: ["", "foo"],
      },
      ...
    ],
    ...
  },
  ...
}

Torrent 2:

{
  info: {
    files: [
      {
        path: ["foo"],
      },
      ...
    ],
    ...
  },
  ...
}

On at least one commonly-used torrent client, these two torrents are stored differently. But parse-torrent sees them as identical, with no way to differentiate the two. This is due to intended behavior of path.join:

Zero-length path segments are ignored.

Proposal

I would just like to have a way to be able to differentiate these torrents.

My proposal is simple: add a pathSegments array to this object:

parse-torrent/index.js

Lines 186 to 191 in 127ae53

return {
path: path.join.apply(null, [path.sep].concat(parts)).slice(1),
name: parts[parts.length - 1],
length: file.length,
offset: files.slice(0, i).reduce(sumLength, 0)
}

I am willing to write a PR for this if I get the go-ahead on the approach.

Warnings installing the latest version

What version of this package are you using?
latest, 7.1.2

What operating system, Node.js, and npm version?
Linux CentOS 7 - npm 6.14.4

What happened?
versions not compatible while installing

What did you expect to happen?
install without warnings or errors

Are you willing to submit a pull request to fix this bug?
I have not this knowledge

/usr/bin/parse-torrent -> /usr/lib/node_modules/parse-torrent/bin/cmd.js
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">=8"} (current: {"node":"6.17.1","npm":"6.14.4"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">=8"} (current: {"node":"6.17.1","npm":"6.14.4"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]
npm WARN notsup Unsupported engine for [email protected]: wanted: {"node":">=8"} (current: {"node":"6.17.1","npm":"6.14.4"})
npm WARN notsup Not compatible with your version of node/npm: [email protected]

parseTorrent.toMagnetURI is not a function

What version of this package are you using?
10.0.1

What operating system, Node.js, and npm version?
Ubuntu 22.04.1 LTS
Node v19.3.0
NPM 9.2.0

What happened?
If I use toMagnetURI like documentation says, I get parseTorrent.toMagnetURI is not a function
Bui if I import like this:
import { toMagnetURI } from 'parse-torrent';
Function works just fine.

What did you expect to happen?
So can you fix the documentation, or code, to make it work properly.

Are you willing to submit a pull request to fix this bug?

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

Once you have installed CI on this repository, you’ll need to re-trigger Greenkeeper’s initial Pull Request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

An in-range update of parse-torrent-file is breaking the build 🚨

☝️ Greenkeeper’s updated Terms of Service will come into effect on April 6th, 2018.

Version 4.1.0 of parse-torrent-file was just published.

Branch Build failing 🚨
Dependency parse-torrent-file
Current Version 4.0.3
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

parse-torrent-file is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 8 commits.

  • e05061c 4.1.0
  • a879110 zuul: drop ie, flaky android, add iphone
  • 671e7db Merge pull request #22 from webtorrent/greenkeeper/bencode-2.0.0
  • d7afa96 fix(package): update bencode to version 2.0.0
  • dd7edf2 remove greenkeeper badge
  • 8d18c6d Merge pull request #17 from webtorrent/greenkeeper/initial
  • 1d308e5 Update README.md
  • 4ed6f36 docs(readme): add Greenkeeper badge

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

deprecation warning on node 7+

node --harmony-async-await --trace-deprecation server

(node:39413) DeprecationWarning: Using Buffer without new will soon stop working. Use new Buffer(), or preferably Buffer.from(), Buffer.allocUnsafe() or Buffer.alloc() instead.
at Buffer (buffer.js:79:13)
at [snip snip]/node_modules/parse-torrent/index.js:109:17
at Object. ([snip snip]/node_modules/parse-torrent/index.js:109:29)
at Module._compile (module.js:573:32)
at Object.Module._extensions..js (module.js:582:10)
at Module.load (module.js:490:32)
at tryModuleLoad (module.js:449:12)
at Function.Module._load (module.js:441:3)
at Module.require (module.js:500:17)
at require (internal/module.js:20:19)

An in-range update of standard is breaking the build 🚨

Version 11.0.0 of standard was just published.

Branch Build failing 🚨
Dependency standard
Current Version 10.0.3
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

standard is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 50 commits.

There are 50 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

infoHash may be undefined in types

The docs say infoHash is guaranteed to be present in the response from parseTorrent(), but the typedefs permit it to be undefined in certain overloads.

An in-range update of blob-to-buffer is breaking the build 🚨

Version 1.2.7 of blob-to-buffer was just published.

Branch Build failing 🚨
Dependency blob-to-buffer
Current Version 1.2.6
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

blob-to-buffer is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 14 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Redundancy - Unify functions

Currently, parse-torrent.remote tries to parse it as non-remote before trying to fetch from remote source index.js#L50-L60.

On WebTorrent it happens too torrent.js#L190-L207

I think parse-torrent should expose one function only (the remote one) as the main and only function.

I also don't understand why this exists if it will be assigned here

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v3
  • actions/setup-node v3
.github/workflows/release.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
npm
package.json
  • bencode ^4.0.0
  • cross-fetch-ponyfill ^1.0.3
  • get-stdin ^9.0.0
  • magnet-uri ^7.0.5
  • queue-microtask ^1.2.3
  • uint8-util ^2.2.4
  • @webtorrent/semantic-release-config 1.0.10
  • brfs 2.0.2
  • semantic-release 21.1.2
  • standard ^17.1.0
  • tape 5.7.5
  • webtorrent-fixtures 2.0.2
  • xtend 4.0.2

  • Check this box to trigger a request for Renovate to run again on this repository

ERR_PACKAGE_PATH_NOT_EXPORTED when importing this package in fastify

What version of this package are you using?
10.0.0

What operating system, Node.js, and npm version?
MacOS Ventura 13.0.1 M1 Pro Chip
Tried on both Node.js v 18.12.1 and 14.21.1
pnpm 7.17.1

What happened?
When I symply import the package with import parseTorrent from "parse-torrent"; I got his error:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/johann/Dev/perso/netflux/backend/node_modules/parse-torrent/package.json
    at new NodeError (internal/errors.js:322:7)
    at throwExportsNotFound (internal/modules/esm/resolve.js:332:9)
    at packageExportsResolve (internal/modules/esm/resolve.js:523:7)
    at resolveExports (internal/modules/cjs/loader.js:450:36)
    at Function.Module._findPath (internal/modules/cjs/loader.js:490:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:101:18)
    at Object.<anonymous> (/Users/johann/Dev/perso/netflux/backend/src/app.ts:3:1)
[ERROR] 16:24:27 Error: No "exports" main defined in /Users/johann/Dev/perso/netflux/backend/node_modules/parse-torrent/package.json

What did you expect to happen?
Being able to import this package in an ES6 env

Are you willing to submit a pull request to fix this bug?
Not sure what's going on so sadly, no.

Edit: Backed to 9.1.5 and everything works fine

From magnet link to .torrent

Is it possible to save the content of a magnet link into a .torrent file ?
At the moment I do this:

var torrentObject = parseTorrent(torrent.url); // torrent.url is the magnet link
var buf = parseTorrent.toTorrentFile(torrentObject);
fs.writeFileSync(blackHole+'/'+torrentObject.name+'.torrent', buf);

It looks like there is a lot more information on the torrent file so this is probably not even possible ...

Roundtripping torrent files through parse-torrent modifes announce lists

What version of this package are you using?
11.0.8 (current version)

What operating system, Node.js, and npm version?
All versions of node

What happened?

decodeTorrentFile flattens the announce-list array, but the nesting inside announce-list has semantic meaning, per BEP 0012. Then encodeTorrentFile has to re-nest but it only has a shallow list so it has to just assume that each announce url had its own top-level element in the list, which is not necessarily the case.

The following script has a minimal reproduction.

import parseTorrent, {toTorrentFile} from 'parse-torrent';
const minimalBencodedMetafile = "d8:announce20:https://example1.com13:announce-listll20:https://example1.com20:https://example2.comee10:created by13:mktorrent 1.14:infod6:lengthi0e4:name7:foo.txt12:piece lengthi32768e6:pieces0:e8:url-listl12:example3.comee"
const decoded = await parseTorrent(Buffer.from(minimalBencodedMetafile));
const encoded = toTorrentFile(decoded);
const roundtripped = Buffer.from(encoded).toString('ascii');
console.log(minimalBencodedMetafile);
console.log(roundtripped);

The output of this script shows that there is an extra el in between the two announce urls after being roundtripped through parse-torrent, changing the shape of the announce tree from [[1, 2]] to [[1], [2]]. The relevant code is below

parse-torrent/index.js

Lines 155 to 160 in 4c0d4ae

if (Array.isArray(torrent['announce-list']) && torrent['announce-list'].length > 0) {
torrent['announce-list'].forEach(urls => {
urls.forEach(url => {
result.announce.push(arr2text(url))
})
})

parse-torrent/index.js

Lines 210 to 213 in 4c0d4ae

torrent['announce-list'] = (parsed.announce || []).map(url => {
if (!torrent.announce) torrent.announce = url
url = text2arr(url)
return [url]

What did you expect to happen?

I expected parse-torrent not to lose fidelity on the shape of the announce-list.

Are you willing to submit a pull request to fix this bug?

I plan to vendor this package into my app and fix it there. I am open to upstreaming the fix, although my fix is likely to be a breaking change.

From .torrent to magnet link

How can I get from this:

parseTorrent.remote(torrentId, function (err, parsedTorrent) {
  if (err) throw err
  console.log(parsedTorrent)
})

To a magnet link?

BitTorrent v2 Support

What version of this package are you using?
9.1.0

What problem do you want to solve?
I want to be able to detect the SHA-256 v2 hash of a v2 Torrent that is parsed with parse-torrent. This also means detecting btmh in addition to btih in Magnet links.

What do you think is the correct solution to this problem?
Adding a infoHashv2 key (or similar) to the resulting object that is generated by parse-torrent

Are you willing to submit a pull request to implement this change?
I will try and learn how parse-torrent works and see what I can do

v10.0.0 — TypeError: parseTorrent.remote is not a function

What version of this package are you using?
10.0.0

What operating system, Node.js, and npm version?
macOS 12.3.1 / Node.js 19.1.0 / npm 9.1.2

What happened?
error message when running the command-line program:

parse-torrent </path/to/torrent>
file:///usr/local/lib/node_modules/parse-torrent/bin/cmd.js:31
  parseTorrent.remote(torrentId, function (err, parsedTorrent) {
               ^

TypeError: parseTorrent.remote is not a function
    at onTorrentId (file:///usr/local/lib/node_modules/parse-torrent/bin/cmd.js:31:16)
    at file:///usr/local/lib/node_modules/parse-torrent/bin/cmd.js:28:6
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

What did you expect to happen?
error-free output & correct parsing

Are you willing to submit a pull request to fix this bug?
no

An in-range update of webtorrent-fixtures is breaking the build 🚨

Version 1.7.1 of webtorrent-fixtures was just published.

Branch Build failing 🚨
Dependency webtorrent-fixtures
Current Version 1.7.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

webtorrent-fixtures is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 4 commits.

  • 8dd86e7 1.7.1
  • d07e2d4 Merge pull request #5 from webtorrent/greenkeeper/brfs-2.0.0
  • 7ec91af readme
  • 62f289a fix(package): update brfs to version 2.0.0

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

filereader instead of 'fs'

Is it possible to use filereader API to parse the torrent file? since fs is not supported in browser and in browserify too

parseTorrent(fs.readFileSync(__dirname + '/torrents/leaves.torrent'))

can we do something like this?

const parseTorrent = require('parse-torrent');
const reader = new FileReader();

reader.readAsArrayBuffer(file);

reader.onload = function () {
      const result = new Int8Array(reader.result);
      var data = parseTorrent(result)
 };

'TypeError: Buffer.alloc is not a function' error on nodejs <5.10.0

I try to run this module, but see the error message like this:

/usr/local/lib/node_modules/parse-torrent/index.js:110
;(function () { Buffer.alloc(0) })()
                       ^

TypeError: Buffer.alloc is not a function
    at /usr/local/lib/node_modules/parse-torrent/index.js:110:24
    at Object.<anonymous> (/usr/local/lib/node_modules/parse-torrent/index.js:110:35)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/parse-torrent/bin/cmd.js:4:20)
    at Module._compile (module.js:409:26)

I have found reason, because of I am using nodejs<5.10.0 .

Maybe you can specify the version of node that your stuff works on in package.json to avoid this.

{ "engines" : { "node" : ">=5.10.0" } }

Thx.

Get more info from magnet

It would be nice to be able to retrieve file lists, torrent name and total size and maybe peers from magnet. I'm trying to combine this with maybe bittorrent-tracker or bittorrent-dht.

An in-range update of brfs is breaking the build 🚨

☝️ Greenkeeper’s updated Terms of Service will come into effect on April 6th, 2018.

Version 1.5.0 of brfs was just published.

Branch Build failing 🚨
Dependency brfs
Current Version 1.4.4
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

brfs is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v1.5.0

the brfs transform now generates source maps in --debug mode.

Commits

The new version differs by 4 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Editing parsed torrent object doesn't change encoded torrent file?

I'm trying to write a script to truncate long filenames inside a torrent file so it'll download successfully using Transmission in an encrypted Linux volume.

I can parse the torrent file, pick out the file paths and names, truncate them and store them back to the object, then use .toTorrentFile to get a buffer I can write to disk. Logging the values from the torrent object, I see the truncated filenames. Inspecting the output file (using the parse-torrent executable), I see the original filenames.

Any advice? Script below.

#!/usr/bin/env node

/* fix-torrent-filenames.js */

const fs = require('fs');
const path = require('path');
const parseTorrent = require('parse-torrent');

const torrentFile = process.argv[2];

if (!torrentFile) {
  console.warn('Usage: ' + path.basename(__filename) + ' <torrent file>');
}

const torrent = parseTorrent(fs.readFileSync(torrentFile));

for (var i = 0; i < torrent.files.length; i++) {
  var file = torrent.files[i];
  var ext = path.extname(file.path.toString());
  var basename = path.basename(file.path.toString()).replace(new RegExp(ext + '$'), '');
  var pathname = path.dirname(file.path.toString());
  var filename = basename.substr(0, 96) + ext;
  torrent.files[i].path = new Buffer(path.join(pathname, filename));
  torrent.files[i].name = new Buffer(filename);
}

const buf = parseTorrent.toTorrentFile(torrent);
fs.writeFileSync(torrentFile + '.new.torrent', buf);

console.log('Wrote ' + buf.length + ' bytes to ' + torrentFile + '.new.torrent');

Incorrect parseTorrent return types

What version of this package are you using?
"@types/parse-torrent": "^5.8.7"
"parse-torrent": "^11.0.16",

What operating system, Node.js, and npm version?
Os: Macos Sonoma
Nodejs version: v21.5.0
npm version: 10.2.4

What happened?
image

What did you expect to happen?
The return types indicated is MagnetUri.instance or ParseTorrentFile.instance but the function return me a promise instead

Possible to parse a torrent file, change the name, then recreate torrent file?

Hi. All I want to do is change the name of a torrent file, without having to feed create-torrent the entire file again. Can I simply parse a torrent file, change the name key, then call parseTorrent.toTorrentFile?

It looks like the encodeTorrentFile function doesn't check the name of the parsed argument, so i'm not sure how to proceed. It does check parsed.info, but that seems to be different than the top level keys found in the create-torrent options, which is where the name option is set.

parse-torrent/index.js

Lines 195 to 198 in 6286abb

function encodeTorrentFile (parsed) {
const torrent = {
info: parsed.info
}

remote() false TypeError [ERR_INVALID_PROTOCOL]

What version of this package are you using?
9.1.3

What operating system, Node.js, and npm version?
MacOS 11.2.3
Node 15.12.0
npm 7.6.3

What happened?
parse-torrent.remote() mistakens a HTTP URL as a magnet, throwing Uncaught TypeError [ERR_INVALID_PROTOCOL]: Protocol "magnet:" not supported. Expected "http:" when passing an HTTP link to a .torrent file.

What did you expect to happen?
Parse-torrent is supposed to call the HTTP link

Support utf-8 encoded comment field

What version of this package are you using?
11.0.14

What problem do you want to solve?
Comment field in torrent files which generated in old application would not use utf-8 as default character encoding, and there files also have an extra utf-8 encoded field, like comment.utf-8. The comment field in these torrent files would have garbled characters by using parse-torrent (see the below screenshot).

image

What do you think is the correct solution to this problem?
Parse the comment content from the utf-8 encoding field first, like processing the name field.

Are you willing to submit a pull request to implement this change?
Yes

An in-range update of tape is breaking the build 🚨

Version 4.9.0 of tape was just published.

Branch Build failing 🚨
Dependency tape
Current Version 4.8.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

tape is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 27 commits.

  • ea6d91e v4.9.0
  • 6867840 [Deps] update object-inspect, resolve
  • 4919e40 [Tests] on node v9; use nvm install-latest-npm
  • f26375c Merge pull request #420 from inadarei/global-depth-env-var
  • 17276d7 [New] use process.env.NODE_TAPE_OBJECT_PRINT_DEPTH for the default object print depth.
  • 0e870c6 Merge pull request #408 from johnhenry/feature/on-failure
  • 00aa133 Add "onFinish" listener to test harness.
  • 0e68b2d [Dev Deps] update js-yaml
  • 10b7dcd [Fix] fix stack where actual is falsy
  • 13173a5 Merge pull request #402 from nhamer/stack_strip
  • f90e487 normalize path separators in stacks
  • b66f8f8 [Deps] update function-bind
  • cc69501 Merge pull request #387 from fongandrew/master
  • bf5a750 Handle spaces in path name for setting file, line no
  • 3c2087a Test name with spaces

There are 27 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of brfs is breaking the build 🚨

The devDependency brfs was updated from 2.0.1 to 2.0.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

brfs is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 4 commits.

  • 660f6d8 2.0.2
  • eb26fec Merge pull request #93 from jagonzalr/pr/update/static-val-version
  • 434cc8b Update static-module from 3.0.0 to 3.0.2
  • 8fafcf5 Remove stray console.log

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

support parsing ArrayBuffer and arraybuffer-view's (typed arrays)

I tried to store the torrent.torrentFile which is a instance of Uint8Array in the browser (not a Buffer)

indexedDB storage accepts cloneable object such as Boolean, ArrayBuffer, Typed Arrays, etc But what is not cloneable is a Node Buffer.

So when I tried to add a torrent with a client.add(uint8arr) it throw a error saying

Error: Invalid torrent identifier

Node's Buffer.isBuffer(obj) don't see typed arrays (or ArrayBuffer) as a buffer.

could you make it so that it can recognize typed array also?


Working with Node's buffer can be a bit of a pain in the ass when it comes to cross web/node environment and I think the use of nodes-buffer is big dependency when ArrayBuffers can do the job at least as good in both environment

Invalid torrent identifier bug

I'm always getting this exception while trying to parse torrent file using:

parseTorrent(fs.readFileSync(path))

It seems to me files are ok since BitTorrent handles them correctly.
Dunno if its ok to give you link here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.