Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jodevak
Copy link

@jodevak jodevak commented Jan 7, 2017

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

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
@jodevak jodevak changed the title Major Fix Major Fix: Downloading Files Just like uTorrent Jan 7, 2017
@jodevak jodevak changed the title Major Fix: Downloading Files Just like uTorrent Major Fix: Downloading Files With Reserved Characters In Thier Names On Windows Jan 8, 2017
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this used anywhere?

Copy link
Author

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) {
Copy link
Collaborator

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?

Copy link
Author

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, '_')
Copy link
Collaborator

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()

Copy link
Author

@jodevak jodevak Jan 9, 2017

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)
}
Copy link
Collaborator

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)),
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants