javascript - Download Torrent File from URL -


i in beginning stages of learning node.js , wanted create simple command line program download .torrent file url given.

let's have following torrent url

https://torcache.net/torrent/3f19b149f53a50e14fc0b79926a391896eabab6f.torrent?title=[kat.cr]ubuntu.15.10.desktop.64.bit

i have following code can contents when save file, not same file downloaded browser.

var fs = require('fs'); var request = require('request');  var url = "https://torcache.net/torrent/3f19b149f53a50e14fc0b79926a391896eabab6f.torrent?title=[kat.cr]ubuntu.15.10.desktop.64.bit"; var file = fs.createwritestream("c:\\test\\test.torrent");  var r = request(url);  r.on('response', function(res){     res.pipe(file); }); 

result this:

1f8b 0800 0000 0000 0203 94b6 63ac 3040 b3ad b96d dbb6 6ddb b66d dbb6 6ddb b66d dbb6 f96e ef3d dfdc 73cf cce4 6492 c9fc ecea 67ad ae54 2ad5 65c2 c165 6867 67ef 6a67 6cca c2cc e56a e2c0 454f efe2 6468 6c6d ea44 676c efe0 60ea e4ec ea64 f69f 838b 3517 1b27 1b27 fd7f d38c ccff 9790 d6c6 d2d9 c5c6 e6ff 9fde d486 85e5 7ff0 f60e a676 4696 2e2e f64e 4ea6 762e ff91 db72 7130 fc3f 04cc ff2d 30b7 b1ff df90 339d 83fb fff4 65e6 f81f be0e ae46 3696 c646 ff2f 8eff 49c1 c2c5 e5ff 642d 1ddc d8e8 fefb 6557 2357 3b17 d7ff 85ff 4f6f ceff 16fc 7fb2 a6ec 5cff 09da fe87 6163 e452 f92f 9ac0 c4de ddce c6de d0c4 d484 c0cc c9de 96e0 7fbb 1018 1b1a 5b98 1218 ba10 fcdf eeff 2b44 6767 ea42 ff9f 521b 3b99 1aba 58da db11 9818 ba98 5a32 b2b0 b0b2 32b0 3371 729a b270 59da 99d9 9bb0 71d9 98da 99bb 5858 3232 b273 3073 b0b1 3033 fde7 cace d0d6 9499 81eb bf52 a465 64a5 6364 a035 3175 b676 b177 a035 b435 6163 a1b3 74b6 6764 e272 b034 3536 25f8 df0e ac4c 2c4c 1c1c a66c ff15 7566 61e1 6463 e0b2 cca2 dd20 bad2 6bd2 5939 9118 bd80 53ee 5a6d b4b9 8173 2c57 5576 ffd9 457f 86e8 4bab b57f ff93 6ace 5608 8696 

am doing thing wrong?

result browser download (partial):

d8:announce43:udp://tracker.coppersurfer.tk:6969/announce13:announce-listll43:udp://tracker.coppersurfer.tk:6969/announceel44:udp://tracker.openbittorrent.com:80/announceel34:udp://glotorrents.pw:6969/announceel38:udp://tracker.publicbt.com:80/announceel44:http://ipv6.torrent.ubuntu.com:6969/announceel39:http://torrent.ubuntu.com:6969/announceee7:comment61:torrent downloaded torrent cache @ http://torcache.net/13:creation datei1445507299e4:infod6:lengthi1178386432e4:name30:ubuntu-15.10-desktop-amd64.iso12:piece lengthi524288e6:pieces44960:iš-Ø"ê^²\ÔähÅèsºÕ±lìq§uswýÝó¾–­oøÿj³›pƒiiyd¹©ÝÈûäÐ 

you're piping buffer object (bytes array, res), that's why have long hexadecimal chain in output file. also, when pipe file, overwrites it, have last chunk downloaded. try this:

request.get({     url: url,     // important, tells request not try parse data, useful binary data     encoding: null,     // torcache gzip torrent file. when piping, request doesn't decompress automically response     gzip: true }).pipe(file); // can pipe directly file, no need listen event 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -