webtorrent/parse-torrent

Zero-length file path segments disappear when they get path.joined

mmgoodnow opened this issue · 0 comments

What version of this package are you using?

9.1.3

What operating system, Node.js, and npm version?

Mac, Node 10, npm 7.6.0

The Situation

I have two torrents with slightly different file structures.
They both are multi-file torrents.

Torrent 1:

{
  info: {
    files: [
      {
        path: ["", "foo"],
      },
      ...
    ],
    ...
  },
  ...
}

Torrent 2:

{
  info: {
    files: [
      {
        path: ["foo"],
      },
      ...
    ],
    ...
  },
  ...
}

On at least one commonly-used torrent client, these two torrents are stored differently. But parse-torrent sees them as identical, with no way to differentiate the two. This is due to intended behavior of path.join:

Zero-length path segments are ignored.

Proposal

I would just like to have a way to be able to differentiate these torrents.

My proposal is simple: add a pathSegments array to this object:

parse-torrent/index.js

Lines 186 to 191 in 127ae53

return {
path: path.join.apply(null, [path.sep].concat(parts)).slice(1),
name: parts[parts.length - 1],
length: file.length,
offset: files.slice(0, i).reduce(sumLength, 0)
}

I am willing to write a PR for this if I get the go-ahead on the approach.