PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Dec 07, 2019 11:42 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: PHP Torrent Decoder
PostPosted: Wed Oct 06, 2010 12:11 am 
Offline
Tranquility In Moderation
User avatar

Joined: Sun Feb 06, 2005 8:18 pm
Posts: 5001
Location: Indiana

_________________
- A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.


Top
 Profile  
 
 Post subject: Re: PHP Torrent Decoder
PostPosted: Thu Oct 07, 2010 1:38 pm 
Offline
DevNet Master
User avatar

Joined: Thu Mar 15, 2007 6:28 pm
Posts: 2765
Location: Redding, California
That's pretty cool. The code is short and sweet. Because I'm not familiar with the Torrent file syntax, I can't really critique the parsing. It would be an interesting challenge to create a PHP torrent download program...

I've only downloaded via torrent like, two times... after seeing your parser I just had to read the Wikipedia page in it :)


Top
 Profile  
 
 Post subject: Re: PHP Torrent Decoder
PostPosted: Thu Oct 07, 2010 2:44 pm 
Offline
Tranquility In Moderation
User avatar

Joined: Sun Feb 06, 2005 8:18 pm
Posts: 5001
Location: Indiana

_________________
- A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.


Top
 Profile  
 
 Post subject: Re: PHP Torrent Decoder
PostPosted: Thu Oct 07, 2010 3:16 pm 
Offline
Briney Mod
User avatar

Joined: Mon Jan 19, 2004 7:11 pm
Posts: 6446
Location: 53.01N x 112.48W
Not much to say about the parsing because, ya - no experience with it.

I would recommend a slight change in how the class is used though. Since it's a single-use class, why not make it static? Also, I'd use camel case for the class name:

Syntax: [ Download ] [ Hide ]
require_once 'torrent_decoder.class.php';
$torrent = TorrentDecoder::decode('path/to/file.torrent');

_________________
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.


Top
 Profile  
 
 Post subject: Re: PHP Torrent Decoder
PostPosted: Thu Oct 07, 2010 3:22 pm 
Offline
DevNet Master
User avatar

Joined: Thu Mar 15, 2007 6:28 pm
Posts: 2765
Location: Redding, California
Interesting idea. Another option would be, instead of being a (static) decoding class, turn it into a Torrent object. Maybe you could even add the functionality to encode a torrent?


Top
 Profile  
 
 Post subject: Re: PHP Torrent Decoder
PostPosted: Fri Oct 08, 2010 1:17 pm 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
I'm against the static stuff. The class already has state. What if later it has more state? For example if a torrent has 50,000 files in it - why parse the whole thing just to get at the name? In this case, you'd be storing even more state and anything you did statically would hinder you or cause global state.

Also it should ideally have better defect localization. How about a way to validate it too?

Ideally it would work like this. Instantiate object pass in data or file stream, be able to call isValidTorrent() and get a boolean. Only if trying to parse before calling isValidTorrent() should I get an exception. Otherwise you're making me use exceptions for non exceptional situations.

You should also have different exception classes for different scenarios, file not found is a LOT different than file invalid, and people might want to catch only one or the other


Top
 Profile  
 
 Post subject: Re: PHP Torrent Decoder
PostPosted: Fri Oct 08, 2010 1:35 pm 
Offline
Tranquility In Moderation
User avatar

Joined: Sun Feb 06, 2005 8:18 pm
Posts: 5001
Location: Indiana

_________________
- A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.


Top
 Profile  
 
 Post subject: Re: PHP Torrent Decoder
PostPosted: Fri Oct 08, 2010 3:25 pm 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida


Top
 Profile  
 
 Post subject: Re: PHP Torrent Decoder
PostPosted: Sat Oct 09, 2010 3:00 am 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4313
Location: Sofia, Bulgaria

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
 Post subject: Re: PHP Torrent Decoder
PostPosted: Sat Oct 09, 2010 3:58 am 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group