Closed BenmasterTM closed 7 years ago
You could use a simple logic:
If the torrent file exists, load it; else, seed and save the torrent file after the metadata is created.
Yea, that what I do, but like I say before, when I try to load the .torrent when the code I show, the torrent appear "loaded" and I get magnet, but when I try to use the magnet, I get no data, but if im use the code of client.seed() I get data in instant.io
I found the problem, for some reason i dont see any error (can be some thing internal) but the mistake are in the torrent params, the "path". I try to check all torrent object diferences from the client.seed() and client.add() and the only diference I see was the "path" value, in the .seed() function, the value is the path without the filename, and in the .add() the path contains the name, so I pass to the params in the .add() the path without the file name, and now works!
Im trying to share existing torrents because every time I start my client, use client.seed() works correctly, but consume to many memory and use many HDD, because internally is creating the file torrent every time i call it, and this is not aceptable because I need to share many small files and take to much time.
I try to create torrents of every file using create-torrent and then, load the torrents with client.add, but dont share the data correctly (the webtorrent client dont see any peer) like the torrent is loaded, but dont seeded.
Here are the codes:
(function(file) { createTorrent( file, { name: path.basename(file), comment: slug(path.basename(file.replace(/\.[^/.]+$/, ""))), createdBy: 'Ben' }, function (err, torrent) { if (!err) { //
torrentis a Buffer with the contents of the new .torrent file fs.writeFile(path.dirname(file) + '/' + slug(path.basename(file.replace(/\.[^/.]+$/, ""))) + '.torrent', torrent) console.log('new torrent created: ' + path.dirname(file) + '/' + slug(path.basename(file.replace(/\.[^/.]+$/, ""))) + '.torrent'); } }); })(results[x]);
This works, appear in the webclient:
/*(function(file) { client.seed(results[x], { name: path.basename(file), comment: slug(path.basename(file.replace(/\.[^/.]+$/, ""))), createdBy: 'Ben' }, function(torrent) { console.log('torrent exists, sharing file: ' + file); var uri = parseTorrent.toMagnetURI(torrent); console.log('magnet string: ' + uri); }); })(results[x]);*/
This show (after many time) one peer, but dont share any data:
(function(file) { fs.readFile(path.dirname(file) + '/' + slug(path.basename(file.replace(/\.[^/.]+$/, ""))) + '.torrent', function read(err, data) { client.add(data, {}, function(torrent) { console.log('loaded :' + file); var uri = parseTorrent.toMagnetURI(torrent); console.log('magnet string: ' + uri); }); } ) })(results[x]);
Exists a way to create the torrent the first time, and then load and share it next times? To dont make client.seed() every time I start the process? Thanks.