From 8cae95652816c126ffb76b5ba77a981acc9060fc Mon Sep 17 00:00:00 2001 From: Denis Kuzmenok Date: Fri, 2 Jun 2017 07:46:28 +0300 Subject: [PATCH] added few helper functions: t.PieceBytesMissing, r.CurrentPos, r.SetNonResponsive --- reader.go | 10 ++++++++++ t.go | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/reader.go b/reader.go index b73b8bad..1c8bce79 100644 --- a/reader.go +++ b/reader.go @@ -44,6 +44,11 @@ func (r *Reader) SetResponsive() { r.responsive = true } +// Disable responsive mode. +func (r *Reader) SetNonResponsive() { + r.responsive = false +} + // Configure the number of bytes ahead of a read that should also be // prioritized in preparation for further reads. func (r *Reader) SetReadahead(readahead int64) { @@ -55,6 +60,11 @@ func (r *Reader) SetReadahead(readahead int64) { r.posChanged() } +// Return reader's current position. +func (r *Reader) CurrentPos() int64 { + return r.pos +} + func (r *Reader) readable(off int64) (ret bool) { if r.t.closed.IsSet() { return true diff --git a/t.go b/t.go index ed810a5f..3fe2ae79 100644 --- a/t.go +++ b/t.go @@ -61,6 +61,14 @@ func (t *Torrent) NumPieces() int { return t.numPieces() } +// Get missing bytes count for specific piece. +func (t *Torrent) PieceBytesMissing(piece int) int64 { + t.cl.mu.Lock() + defer t.cl.mu.Unlock() + + return int64(t.pieces[piece].bytesLeft()) +} + // Drop the torrent from the client, and close it. It's always safe to do // this. No data corruption can, or should occur to either the torrent's data, // or connected peers. -- 2.48.1