Socket
Socket
Sign inDemoInstall

torrent-piece

Package Overview
Dependencies
2
Maintainers
9
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    torrent-piece

Torrent piece abstraction


Version published
Weekly downloads
3.7K
increased by26.95%
Maintainers
9
Install size
39.3 kB
Created
Weekly downloads
 

Readme

Source

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

import Piece from '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.

Keywords

FAQs

Last updated on 23 Jul 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc