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:
authorFeross Aboukhadijeh <feross@feross.org>2015-03-20 05:48:15 +0300
committerFeross Aboukhadijeh <feross@feross.org>2015-03-20 05:48:15 +0300
commitc132ce47c9146738a0e7a5700aa93409b680b524 (patch)
tree2a674a9dad5ff0b9f50f600daf664ee3b14997b3 /lib/fs-storage.js
parentc254fda44c7d498f08b73e134b7994f0394a9e29 (diff)
internal: simplify how storage opts are passed
Diffstat (limited to 'lib/fs-storage.js')
-rw-r--r--lib/fs-storage.js22
1 files changed, 9 insertions, 13 deletions
diff --git a/lib/fs-storage.js b/lib/fs-storage.js
index 7923791..51e5ea5 100644
--- a/lib/fs-storage.js
+++ b/lib/fs-storage.js
@@ -1,6 +1,5 @@
module.exports = FSStorage
-var extend = require('xtend')
var fs = require('fs')
var inherits = require('inherits')
var mkdirp = require('mkdirp')
@@ -11,8 +10,7 @@ var rimraf = require('rimraf')
var Storage = require('./storage')
var thunky = require('thunky')
-var TMP = fs.existsSync('/tmp') ? '/tmp' : os.tmpDir()
-function noop () {}
+var TMP = path.join(fs.existsSync('/tmp') ? '/tmp' : os.tmpDir(), 'webtorrent')
inherits(FSStorage, Storage)
@@ -24,18 +22,16 @@ inherits(FSStorage, Storage)
*/
function FSStorage (parsedTorrent, opts) {
var self = this
- opts = extend({
- nobuffer: true,
- tmp: TMP,
- name: 'webtorrent'
- }, opts)
- Storage.call(self, parsedTorrent, opts)
- self.path = opts.path || path.join(opts.tmp, opts.name, parsedTorrent.infoHash)
- self.piecesMap = []
+ self.tmp = opts.tmp || TMP
+ self.path = opts.path || path.join(self.tmp, parsedTorrent.infoHash)
+ self.piecesMap = []
self.nonExistentError = new Error('Cannot read from non-existent file')
+ opts.nobuffer = true
+ Storage.call(self, parsedTorrent, opts)
+
self.files.forEach(function (file) {
var fileStart = file.offset
var fileEnd = fileStart + file.length
@@ -179,7 +175,7 @@ FSStorage.prototype._onPieceDone = function (piece) {
*/
FSStorage.prototype.remove = function (cb) {
var self = this
- if (!cb) cb = noop
+ if (!cb) cb = function () {}
self.close(function (err) {
if (err) return cb(err)
@@ -193,7 +189,7 @@ FSStorage.prototype.remove = function (cb) {
*/
FSStorage.prototype.close = function (cb) {
var self = this
- if (!cb) cb = noop
+ if (!cb) cb = function () {}
if (self.closed) return cb()
Storage.prototype.close.call(self, function (err) {