Closed LostBeard closed 5 months ago
The file names work as expected with 2 or more files.
Hi @LostBeard
The issue you're seeing appears to be the intended behaviour of create-torrent
, with the logic defined here: https://github.com/webtorrent/create-torrent/blob/510d917abbc3b61818427bd9911c3c86a9251ef0/index.js#L83
When one file is seeded, the code above will change the file's name to opts.name
if a name isn't passed through with the file.
If this is not desirable, let me know, and we can possibly look at implementing an option to override/ignore this.
When one file is seeded, the code above will change the file's name to opts.name if a name isn't passed through with the file.
A File object has a name.
I can understand for all of the other inputs that can be passed in.
As you can see in my example, the name from the torrent is being used even though File has a name property. The code you are showing seems to show that the name property from File should be used, but that is not what is happening.
The above logic should respect the input object's name property if one exists. I'll look into this and see what's causing it to get mangled.
Thank you.
After looking into this further, the reason why this occurs is that:
.torrent
only contains one file, the file.name
is discarded and only the torrent.name
is stored..torrent
contains more than one file, the full file path is stored as this is required to recreate the folder structure fully.This is the documented and expected behaviour for a .torrent
when operating in single file mode and multiple file mode as documented in BEP 3:
In the single file case, the name key is the name of a file, in the multiple file case, it's the name of a directory.
Sources: https://www.bittorrent.org/beps/bep_0003.html https://wiki.theory.org/BitTorrentSpecification#Info_in_Single_File_Mode
It is expected behavior. Thank you for the information. I have been looking at the code and noticed the isSingleFileTorrent
bool assuming it meant special handling of the torrent.
I suppose if I want the single file's name kept I will have to have 2+ files or just name the torrent the file's name. Makes sense though.
Thank you again. 👍
Posted in the webtorrent repo issues as webtorrent/webtorrent#2808
What version of this package are you using? WebTorrent 2.3.6
What operating system, Node.js, and npm version? Chrome 64 bit
What happened? When seeding a torrent with 1 file, the file's name in the torrent is set to the name of the torrent.
I am using WebTorrent below, but internally it is calling
createTorrent
What did you expect to happen? I expected the file to keep its own name and not take on the name of the torrent.
Are you willing to submit a pull request to fix this bug? If I can find the bug, yes.
Maybe this is expected behavior for single file torrents?