Methods
file.select([priority])
Selects the file to be downloaded.
Priority level for downloading this file
file.deselect()
Deselects the file, which means it won’t be downloaded unless a stream is created for it.
file.createReadStream([opts])
Create a Node.js readable stream to the file.
Node.js readable stream
file.stream([opts])
Create a W3C ReadableStream to the file.
W3C ReadableStream
file[Symbol.asyncIterator]([opts])
Create an async iterator to iterate over file chunks.
Async iterator yielding Uint8Array chunks
file.arrayBuffer([opts])
Get the file contents as an ArrayBuffer.
Promise resolving to ArrayBuffer
file.blob([opts])
Get a W3C Blob object which contains the file data.
Promise resolving to Blob
file.streamTo(elem) (browser only)
Sets the element source to the file’s streaming URL. Requires client.createServer() to be called first.
Video or audio element
The same element passed in
Supports:
- All major video containers (MP4, WebM, MKV, etc.)
- All major audio containers (MP3, AAC, Opus, etc.)
- Streaming and seeking
- Browser native codecs only
file.includes(piece)
Check if the piece number contains this file’s data.
Piece index
True if file includes this piece
Properties
file.name
File name as specified by the torrent
file.path
File path as specified by the torrent
file.length / file.size
File length in bytes
file.type
MIME type of the file. Defaults to
'application/octet-stream' if unknown.file.downloaded
Total verified bytes received for this file
file.progress
File download progress, from 0 to 1
file.done
True when the file has been downloaded
file.streamURL
URL of the file recognized by the HTTP server. Requires
client.createServer() to be called first.Events
file.on('done', callback)
Emitted when the file has been downloaded.
file.on('stream', callback)
Emitted every time the HTTP server creates a new read stream (e.g., when the user seeks a video).
This is advanced functionality for manipulating streamed data.
file.on('iterator', callback)
Emitted when the HTTP server creates an async iterator.
This is advanced functionality for low-level data manipulation.