torrent-piece

WebJar for torrent-piece

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

torrent-piece
Last Version

Last Version

2.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

torrent-piece
WebJar for torrent-piece
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/webtorrent/torrent-piece

Download torrent-piece

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/torrent-piece/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>torrent-piece</artifactId>
    <version>2.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/torrent-piece/
implementation 'org.webjars.npm:torrent-piece:2.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/torrent-piece/
implementation ("org.webjars.npm:torrent-piece:2.0.0")
'org.webjars.npm:torrent-piece:jar:2.0.0'
<dependency org="org.webjars.npm" name="torrent-piece" rev="2.0.0">
  <artifact name="torrent-piece" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='torrent-piece', version='2.0.0')
)
libraryDependencies += "org.webjars.npm" % "torrent-piece" % "2.0.0"
[org.webjars.npm/torrent-piece "2.0.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

torrent-piece ci npm downloads javascript style guide

Torrent piece abstraction

Sauce Test Status

Also works in the browser with browserify! This module is used by WebTorrent and torrent-stream.

install

npm install torrent-piece

usage

const Piece = require('torrent-piece')

Piece.BLOCK_LENGTH // 16384

const pieceLength = Piece.BLOCK_LENGTH * 5
const piece = new Piece(pieceLength)
piece.missing // 81920

piece.reserve() // 0
piece.set(0, someBuffer0)

piece.reserve() // 1
piece.reserve() // 2
piece.reserve() // 3

piece.set(1, someBuffer1)
piece.set(2, someBuffer2)
piece.set(3, someBuffer3)

piece.reserve() // 4
piece.cancel(4) // cancel the reservation of a chunk

piece.reserve() // 4 (given out again)
piece.set(4, someBuffer4)

// handy functions
piece.chunkLength(0) // 16384
piece.chunkOffset(0) // 0

// eventually, when no more chunks left...

piece.reserve() // -1 (signal that all chunks are reserved)
piece.missing // 0

const pieceBuffer = piece.flush()
console.log(pieceBuffer)

license

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

org.webjars.npm

WebTorrent

⚡️⚡️⚡️ Streaming torrent client for the web, Node.js, Mac, Windows, & Linux.

Versions

Version
2.0.0