Socket
Book a DemoInstallSign in
Socket

locate-torrent-data

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

locate-torrent-data

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

latest
Source
npmnpm
Version
0.2.3
Version published
Maintainers
1
Created
Source

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

Keywords

bittorrent

FAQs

Package last updated on 08 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts