npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@z-torrent/create

v0.0.13

Published

Create .torrent files

Downloads

977

Readme

@z-torrent/create

Create BitTorrent .torrent files from files, folders, buffers, blobs, or readable streams. Used by Z-Torrent. Works in Node.js; browser usage is supported for non-filesystem inputs (paths require Node).

Install

npm install @z-torrent/create

Usage

import fs from 'fs'
import { createTorrent } from '@z-torrent/create'

createTorrent('/path/to/folder', (err, torrent) => {
  if (!err) {
    // torrent is a Uint8Array with the .torrent payload
    fs.writeFileSync('my.torrent', torrent)
  }
})

A reasonable piece length (roughly ~1024 pieces) is chosen automatically unless you override it (see options below).

API

createTorrent(input, [opts], callback)

  • input: string path, File / Blob, Uint8Array, Node.js Readable, or an array mixing those types. FileList is accepted. Paths only work in Node (not in the browser bundle).
  • opts: optional. Shapes include:
    • name, comment, createdBy, creationDate
    • private, pieceLength, maxPieceLength
    • announce, announceList, urlList
    • info — extra keys merged into the info dictionary (e.g. source for cross-seeding)
    • filterJunkFiles — default true
    • sslCert — optional ssl-cert in info
    • onProgress(hashedLength, totalLength)
  • callback: (err, torrent?: Uint8Array) => void

If announce / announceList are omitted, default trackers are added (including WebRTC wss:// trackers for browser-oriented swarms).

parseInput(input, [opts], callback)

Low-level helper: parses/normalizes input and returns the internal file list and whether the torrent is treated as single-file. The main consumer in this repo is the Node client when seeding.

announceList

Exported default tracker tier list (array of single-URL arrays), same as used when no custom announce options are passed.

Types

CreateTorrentOptions, FileItem, and CreateTorrentOptions-related shapes are exported for TypeScript.

BitTorrent v2 / hybrid (BEP 52)

Pass protocolVersion in options:

  • 'v1' (default) — classic SHA1 piece layer
  • 'v2' — metadata v2 only (SHA-256 merkle piece layer via @z-torrent/merkle-tree)
  • 'hybrid' — v1 and v2 in one .torrent for compatibility

pieceLength for v2 / hybrid is normalized to BEP 52 rules (power of two, ≥ 16 KiB leaf blocks). Hybrid torrents require each file to have a path.

Memory: for v2 / hybrid, each source file is read fully into memory to build per-file merkle metadata (unlike the streaming SHA-1 path for plain v1). Very large inputs may need more RAM; consider raising Node memory limits or using v1 for huge seeds until streaming merkle creation exists.

Global: WEBTORRENT_ANNOUNCE

If set on globalThis to a string or string[], those URLs are appended to the announce list. (Legacy name from WebTorrent; behaviour is the same for Z-Torrent.)

CLI

The create-torrent binary is published with this package:

create-torrent <file-or-directory> [-o out.torrent] [options]

Use -o to write a file; otherwise the torrent is written to stdout.

License

MIT