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
diff options
context:
space:
mode:
-rw-r--r--docs/api.md10
-rw-r--r--lib/torrent.js30
-rw-r--r--package.json2
3 files changed, 22 insertions, 20 deletions
diff --git a/docs/api.md b/docs/api.md
index 74622b4..2491fa5 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -105,9 +105,11 @@ If `opts` is specified, then the default options (shown below) will be overridde
maxWebConns: Number, // Max number of simultaneous connections per web seed [default=4]
path: String, // Folder to download files to (default=`/tmp/webtorrent/`)
private: Boolean, // If true, client will not share the hash with the DHT nor with PEX (default is the privacy of the parsed torrent)
- store: Function // Custom chunk store (must follow [abstract-chunk-store](https://www.npmjs.com/package/abstract-chunk-store) API)
+ store: Function, // Custom chunk store (must follow [abstract-chunk-store](https://www.npmjs.com/package/abstract-chunk-store) API)
destroyStoreOnDestroy: Boolean // If truthy, client will delete the torrent's chunk store (e.g. files on disk) when the torrent is destroyed
- storeCacheSlots: Number // Number of chunk store entries (torrent pieces) to cache in memory [default=20]; 0 to disable caching
+ storeCacheSlots: Number, // Number of chunk store entries (torrent pieces) to cache in memory [default=20]; 0 to disable caching
+ storeOpts: Object, // Custom options passed to the store
+ addUID: Boolean, // (Node.js only) If true, the torrent will be stored in it's infoHash folder to prevent file name collisions (default=false)
skipVerify: Boolean, // If true, client will skip verification of pieces for existing store and assume it's correct
preloadedStore: Function, // Custom, pre-loaded chunk store (must follow [abstract-chunk-store](https://www.npmjs.com/package/abstract-chunk-store) API)
strategy: String // Piece selection strategy, `rarest` or `sequential`(defaut=`sequential`)
@@ -125,9 +127,13 @@ just want the file data, then use `ontorrent` or the 'torrent' event.
If you provide `opts.store`, it will be called as
`opts.store(chunkLength, storeOpts)` with:
+* `storeOpts` - custom `storeOpts` specified in `opts`
* `storeOpts.length` - size of all the files in the torrent
* `storeOpts.files` - an array of torrent file objects
+* `storeOpts.torrent` - the torrent instance being stored
+* `storeOpts.path` - path to the store, based on `opts.path`
* `storeOpts.name` - the info hash of the torrent instance being stored
+* `storeOpts.addUID` - boolean which tells the store if it should include an UID in it's file paths
**Note:** Downloading a torrent automatically seeds it, making it available for download by other peers.
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)
diff --git a/package.json b/package.json
index a2c9e2c..6afd0b0 100644
--- a/package.json
+++ b/package.json
@@ -48,7 +48,7 @@
"debug": "^4.3.2",
"end-of-stream": "^1.4.4",
"escape-html": "^1.0.3",
- "fs-chunk-store": "^2.0.3",
+ "fs-chunk-store": "^2.0.4",
"http-node": "github:webtorrent/http-node#webtorrent",
"immediate-chunk-store": "^2.2.0",
"load-ip-set": "^2.2.1",