npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

locate-torrent-data

v0.2.3

Published

Find the location of files that match the contents of a torrent file.

Downloads

2

Readme

node-locate-torrent-data

NPM Package Build Status Coverage Status Dependency Status

Example

var locateTorrentData = require("locate-torrent-data");
var fileIndex = locateTorrentData.index("D:\\Files");
var torrentPath = "C:\\Torrents\\memes.torrent";
fileIndex.search(torrentPath, function (error, files) {
  var found = files.reduce(function (count, file) {
    if (file.location) {
      return count + 1;
    }
    return count;
  }, 0);
  console.log("Files found: " + found + " / " + files.length);
});

Installation

npm i locate-torrent-data

API Reference

locate-torrent-data.index(path, [options], [callback]) ⇒ FileIndex

Create a searchable file index from the contents of specified folder(s).

Kind: static method of locate-torrent-data
Emits: error, update
Params

  • path string | Array.<string>
  • [options] Object
    • [.maxdepth] number
    • [.dereference] boolean
  • [callback] function
    • .error Error

Example

var fileIndex = locateTorrentData.index("D:\\Files");

locate-torrent-data.load(source, [callback]) ⇒ FileIndex

Import a file index from disk or read from specified stream.

Kind: static method of locate-torrent-data
Emits: error, update
See: save
Params

  • source string | Readable
  • [callback] function
    • .error Error

Example

var fileIndex = locateTorrentData.load("~/fileindex.csv");

FileIndex

Kind: global class

fileIndex.search(torrent, [forEach], [callback]) ↩︎

Search file index for files that match the contents of specified torrent.

Kind: instance method of FileIndex
Chainable
Emits: error, match, notFound, end, update
Params

Example

var torrentPath = "C:\\Torrents\\memes.torrent";
var savePath = "D:\\Seeding";
var torrent = parseTorrentFile(fs.readFileSync(torrentPath));
fileIndex.search(torrent, function (file, callback) {
  var dest = path.join(savePath, torrent.name, file.path);
  fs.rename(file.location, dest, callback);
}, function (error, files) {
  if (error) {
    console.error(error);
    return;
  }
  fs.unlinkSync(torrentPath);
});

fileIndex.on(event, callback) ↩︎

Add event listener.

Kind: instance method of FileIndex
Chainable
Params

  • event string
  • callback function

Example

fileIndex
  .on("error", function (error) {
    console.error(error);
  })
  .on("match", function (file, torrent) {
    var dest = path.join("D:\\Seeding", torrent.name, file.path);
    fs.rename(file.location, dest, function () {
      console.log("File located and moved: " + file.name);
    });
  })
  .on("notFound", function (file, torrent) {
    console.log("File not found: " + file.name);
  })
  .on("end", function (files, torrent) {
    var found = files.reduce(function (count, file) {
      if (file.location) {
        return count + 1;
      }
      return count;
    }, 0);
    console.log("Files found: " + found + " / " + files.length);
  })
  .on("update", function () {
    console.log("File index updated.");
  });
var torrentPath = "C:\\Torrents";
fs.readdirSync(torrentPath).forEach(function (file) {
  if (file.endsWith(".torrent")) {
    fileIndex.search(path.join(torrentPath, file));
  }
});

fileIndex.add(path, [options], [callback]) ↩︎

Add contents of specified folder(s) to the file index.

Kind: instance method of FileIndex
Chainable
Emits: error, update
Params

  • path string | Array.<string>
  • [options] Object
    • [.maxdepth] number
    • [.dereference] boolean
  • [callback] function
    • .error Error

Example

var fileIndex = locateTorrentData.index("D:\\Files");
fileIndex.add("D:\\Files2");

fileIndex.remove(path, [callback]) ↩︎

Remove contents of specified folder(s) from the file index.

Kind: instance method of FileIndex
Chainable
Emits: update
Params

  • path string | Array.<string>
  • [callback] function

Example

var fileIndex = locateTorrentData.index("D:\\Files");
fileIndex.remove("D:\\Files\\Secret Files");

fileIndex.save(destination, [callback]) ↩︎

Export file index as csv file to disk at specified path or write to specified stream.

Kind: instance method of FileIndex
Chainable
Emits: error
See: load
Params

  • destination string | Writable
  • [callback] function
    • .error Error

Example

fileIndex.save("~/fileindex.csv");

"error" (error)

Kind: event emitted by FileIndex
See: on
Params

  • error Error

"match" (file, torrent)

Kind: event emitted by FileIndex
See: on
Params

"notFound" (file, torrent)

Kind: event emitted by FileIndex
See: on
Params

"end" (files, torrent)

Kind: event emitted by FileIndex
See: on
Params

"update"

Kind: event emitted by FileIndex
See: on

TorrentFile

Kind: global class
Properties

  • offset number - Offset of file inside torrent.
  • length number - File size in bytes.
  • name string - File name inside torrent.
  • path string - Path of file inside torrent.
  • location string - Location on disk of matching file if found.

License

MPL 2.0