Coder Social home page Coder Social logo

thaunknown / bt-fetch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rangermauve/bt-fetch

0.0 1.0 0.0 162 KB

Interact with Bittorrent the same way you would websites via fetch()

License: GNU Affero General Public License v3.0

JavaScript 100.00%

bt-fetch's Introduction

bt-fetch

Interact with Bittorrent the same way you would websites via fetch() and bittorrent:// or bt:// URLs

How it works

  • Uses WebTorrent to load torrents
  • bittorrent:// URLs put the infohash of a torrent into the hostname portion
  • bittorrent:// URLs can contain an individual file to prioritize downloading
  • bittorrent:// URLs can point to a folder path to get a listing

API

import makeBTFetch from 'bt-fetch'

const fetch = makeBTFetch({
  // Use this if you want things to be downloaded somewhere specific
  folder: '~/.local/data/bt-fetch/'
  // You can also pass any arguments from `new WebTorrent` and `client.add`
})

// Get a file as text
const res = fetch('bittorrent://08ada5a7a6183aae1e09d831df6748d566095a10/example.html')

const content = await res.text()

// How big is the file in bytes (useful in HEAD requests)
const length = res.headers.get('Content-Length')
// How much of the file has been downloaded in bytes
const downloaded = res.headers.get('X-Downloaded')

// List files / subfolders as JSON
const res = await fetch('bittorrent://infohash/path/')

const files = await res.json()

// List the contents as a web page
const res = await fetch('bittorrent://infohash/path/', {headers: {
  Accept: 'text/html'
})

const page = await res.text()

// now also supports public keys bittorrent://64CharacterPublicKeyHere
const pubRes = fetch('bittorrent://1e267e045c1abcb9af26df782a048a1cfd2d26e6db23ff5026b213ce037301bf')

TODO

  • Pass querystring params from magnet link info (trackers, etc)
  • Support index.html resolution (with opt-out)
  • Creating torrents using POST
  • Mutable torrent record exchange (updates without DHT polling)
  • Support some sort of DNS based on DNSLink
  • Extension messages with EventSource a-la hypercore-fetch

bt-fetch's People

Contributors

rangermauve avatar resession avatar thaunknown avatar

Watchers

 avatar

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.