New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Major Fix: Downloading Files With Reserved Characters In Thier Names On Windows #178
base: master
Are you sure you want to change the base?
Conversation
Major fix, torrent-stream is now able to download files with reserved characters in their names (e.g. ':'), Manget to test magnet:?xt=urn:btih:LOSJHGQAVGZBMKNAVV6TO2EYW5UNTF5D&dn=Scikit-learn_%20Machine%20Learning%20in%20Python.pdf&tr=http%3A%2F%2Facademictorrents.com%2Fannounce.php&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&xl=42310
Code re-organized with npm javascript standard
@@ -97,6 +96,7 @@ var torrentStream = function (link, opts, cb) { | |||
engine.infoHash = infoHash | |||
engine.metadata = metadata | |||
engine.path = opts.path | |||
engine.ex = exchangeMetadata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it in my last commit .
@@ -125,12 +125,34 @@ var torrentStream = function (link, opts, cb) { | |||
} | |||
}) | |||
|
|||
var handleReserved = function (p) { | |||
this.replaceAt = function (str, index, character) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this
here? is it global
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it in my last commit .
var hold = s[i] | ||
for (var cnt = 0; cnt < hold.length && (s[i] + path.sep) !== root; ++cnt) { | ||
if (reser.indexOf(hold[cnt]) !== -1) { | ||
hold = this.replaceAt(hold, cnt, '_') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this would be much simpler if you used regexp and .replace()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes , you are right, i just wanted the project owners to get into the point that its not only parsing the file name, but the full 'given' path of the file. Anyway, ive made a new modification using regexp and .replace()
, i hope you have a look to it.
thanks,
++i | ||
} | ||
return n.join(path.sep) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it have to be this complicated? Can't you just do split()
-> map()
-> replace()
-> join()
?
engine.store = ImmediateChunkStore(storage(torrent.pieceLength, { | ||
files: torrent.files.map(function (file) { | ||
return { | ||
path: path.join(opts.path, file.path), | ||
path: handleReserved(path.join(opts.path, file.path)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should only handle file.path
Major fix, torrent-stream is now able to download files with reserved characters in windows file system,
for example assume we have the file's path in the torrent like this dir1/python:introduction.pdf
With this fix the name of the file will be parsed to python_introduction.pdf and the : will be replaced with _ and so on with any other reserved characters.
Manget to test :
magnet:?xt=urn:btih:LOSJHGQAVGZBMKNAVV6TO2EYW5UNTF5D&dn=Scikit-learn_%20Machine%20Learning%20in%20Python.pdf&tr=http%3A%2F%2Facademictorrents.com%2Fannounce.php&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&xl=42310