Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorCas <6506529+ThaUnknown@users.noreply.github.com>2021-10-25 18:18:55 +0300
committerGitHub <noreply@github.com>2021-10-25 18:18:55 +0300
commit6cd9b5f74d7cd676259cd11daa2a568a3c5666d9 (patch)
treeb784569c790a612c55ef7a7b5211f839fdbdffbf /lib
parentd63bf59c092f6b8f4e201071b87ab0f0b643e14d (diff)
fix: add storeOpts, specify store path, align with docs (#2121)
* fix: add storeOpts, specify store path, align with docs * make changes non-breaking by default * debatable documentation update * add torrent name to store name * reduce hash name * Update lib/torrent.js * fix filegetmodtimes * bump fs chunk store Co-authored-by: Diego Rodríguez Baquero <github@diegorbaquero.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/torrent.js30
1 files changed, 13 insertions, 17 deletions
diff --git a/lib/torrent.js b/lib/torrent.js
index 3d4730f..78695c0 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -73,7 +73,8 @@ class Torrent extends EventEmitter {
this.announce = opts.announce
this.urlList = opts.urlList
- this.path = opts.path
+ this.path = opts.path || TMP
+ this.addUID = opts.addUID || false
this.skipVerify = !!opts.skipVerify
this._store = opts.store || FSChunkStore
this._preloadedStore = opts.preloadedStore || null
@@ -102,6 +103,7 @@ class Torrent extends EventEmitter {
this.metadata = null
this.store = null
+ this.storeOpts = opts.storeOpts
this.files = []
this.pieces = []
@@ -229,8 +231,6 @@ class Torrent extends EventEmitter {
return this._destroy(new Error('Malformed torrent data: No info hash'))
}
- if (!this.path) this.path = path.join(TMP, this.infoHash)
-
this._rechokeIntervalId = setInterval(() => {
this._rechoke()
}, RECHOKE_INTERVAL)
@@ -473,21 +473,18 @@ class Torrent extends EventEmitter {
this._rarityMap = new RarityMap(this)
+ this.files = this.files.map(file => new File(this, file))
+
let rawStore = this._preloadedStore
if (!rawStore) {
rawStore = new this._store(this.pieceLength, {
- // opts.torrent is deprecated (replaced by the name property).
- // it doesn't appear to be used by current versions of any stores on npm.
- torrent: {
- infoHash: this.infoHash
- },
- files: this.files.map(file => ({
- path: path.join(this.path, file.path),
- length: file.length,
- offset: file.offset
- })),
+ ...this.storeOpts,
+ torrent: this,
+ path: this.path,
+ files: this.files,
length: this.length,
- name: this.infoHash
+ name: this.name + ' - ' + this.infoHash.slice(0, 8),
+ addUID: this.addUID
})
}
@@ -502,8 +499,6 @@ class Torrent extends EventEmitter {
rawStore
)
- this.files = this.files.map(file => new File(this, file))
-
// Select only specified files (BEP53) http://www.bittorrent.org/beps/bep_0053.html
if (this.so) {
this.files.forEach((v, i) => {
@@ -587,7 +582,8 @@ class Torrent extends EventEmitter {
getFileModtimes (cb) {
const ret = []
parallelLimit(this.files.map((file, index) => cb => {
- fs.stat(path.join(this.path, file.path), (err, stat) => {
+ const filePath = this.addUID ? path.join(this.name + ' - ' + this.infoHash.slice(0, 8)) : path.join(this.path, file.path)
+ fs.stat(filePath, (err, stat) => {
if (err && err.code !== 'ENOENT') return cb(err)
ret[index] = stat && stat.mtime.getTime()
cb(null)