mafintosh / torrent-stream

The low level streaming torrent engine that peerflix uses
MIT License
1.94k stars 228 forks source link

Keep files that were selected elsewhere #114

Closed nevercast closed 8 years ago

nevercast commented 9 years ago

Hello,

I couldn't find any questions that matched this one so I've posted mine. Is there a way to determine (Without tracking files in my own application, avoiding redundancy) if a file was selected for full download instead of the entire file just being streamed.

In some cases when streaming a file to clients, a client might elect to have the file saved so that it's available again in the future without re-downloading.

I intend to have a cache folder for all streamed files that is cleared oldest first to prevent my HDD filling up as content is streamed. Is there a way to easily determine if the file was selected (and should be moved to be kept) ?

I wish to listen for the download event and move the file to another location so that it is not aged-off my HDD at a later stage.

asapach commented 9 years ago

First off, this seems like a bad idea, since it contradicts the bittorrent protocol expectations: one a peer has downloaded a piece, it should be able to seed it. If you delete the downloaded file, you will be unable to do so, and will break the protocol. So unless you become a leech (never seed) or leave the swarm entirely (don't make or accept peer connections), you can't delete the stored files.

I wish to listen for the download event and move the file to another location so that it is not aged-off my HDD at a later stage.

I believe 'download' event is emitted for each downloaded piece, not file. So you'd first have to check if a file is downloaded completely.

Is there a way to easily determine if the file was selected (and should be moved to be kept) ?

Selected means that t-s will try to download all the pieces that comprise a file. You can check the selection property, here's an example. Whether it's complete is a different story entirely: #113. Once a file is complete, it's no longer selected.

nevercast commented 9 years ago

Thank you very much for your response, I do not wish to damage the health of torrents but I don't wish to stay seeding for long periods of time because I don't have the HDD space to keep every item I watch. Perhaps I could remove/move it after a seed ratio is achieved.

I'll play around with it more, thanks for the links.