Permalink
Browse files

Merge branch 'release/0.3.1'

  • Loading branch information...
2 parents 5d657e0 + 1751d05 commit 1c0417980dbf0bda486c79af3901ec01fd4d4787 @deoxxa committed Dec 21, 2011
Showing with 35 additions and 1 deletion.
  1. +34 −0 lib/torrent-util.js
  2. +1 −1 package.json
View
34 lib/torrent-util.js
@@ -1,3 +1,19 @@
+function flatten(subject, res) {
+ if (!res) {
+ res = [];
+ }
+
+ if (typeof subject == "object" && subject instanceof Array) {
+ subject.forEach(function(el) {
+ flatten(el, res);
+ });
+ } else {
+ res.push(subject);
+ }
+
+ return res;
+}
+
/**
* Just a little optimisation to save on a bunch of regexing later.
*/
@@ -135,3 +151,21 @@ exports.get_files = function(torrent) {
size: this.get_size(torrent),
}];
};
+
+exports.get_trackers = function(torrent) {
+ if (typeof torrent != "object") {
+ return null;
+ }
+
+ return flatten([torrent["announce-list"], torrent.announce]).map(function(tracker) {
+ if (Buffer.isBuffer(tracker)) {
+ tracker = tracker.toString();
+ }
+
+ if (typeof tracker == "string") {
+ return tracker;
+ }
+ }).filter(function(tracker) {
+ return !!tracker;
+ });
+};
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "torrent-util",
"description": "Various utility functions for making sense of .torrent files",
- "version": "0.2.2",
+ "version": "0.3.1",
"author": {
"name": "Conrad Pankoff",
"email": "deoxxa@fknsrs.biz",

0 comments on commit 1c04179

Please sign in to comment.