• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSData, chars, and torrent files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSData, chars, and torrent files


  • Subject: Re: NSData, chars, and torrent files
  • From: Duncan Anker <email@hidden>
  • Date: Thu, 25 May 2006 12:55:00 +1000

Hi Jon,

Jon Shier wrote:
I'm about at the end of my rope with this. As an attempt to learn Cocoa (and OO programming in general) I'm writing my own BitTorrent client. But I can't seem to get past a basic problem: I can't read the contents of a .torrent file into an easily accessible data structure with any success. I initially read it into an NSString, but that corrupted the SHA1 hashes that are in the file as raw byte strings. Then, on advice from Allan Odgaard (yay IRC!), I switched to using an NSData object to initially read the file, then converting it to a const char * so I can iterate through it and parse the data (which, by the way, worked file when I was using an NSString). However, this doesn't seem to work. The char I get is only a fraction of the NSData object (I can tell the NSData object has all of the file in it because of its length), always terminating at some point in the SHA1 hash data.
Not knowing much about the structure of a .torrent file, but assuming certain pieces of it are fixed, can you not just use something like (usual off the top of one's head disclaimers apply):

NSData *myData = [[NSData dataWithContentsOfMappedFile: myFile] retain];
NSData *theDataThatIWant = [myData subdataWithRange:theRangeOfWhatIWant];

etc

You probably want to iterate through (if you need to iterate) with cocoa data objects rather than raw pointers. At the very least, I'm not sure why you would pass a raw pointer to your receivers when you have a perfectly good NSData object.
P.S. Any algorithmic improvements or ideas you want to offer for .torrent file parsing would also be appreciated.
Use collection enumerators for array iteration rather than for loops with objectAtIndex, maybe?
[NSMutable Dictionary dictionary] is probably more easily understood than [[[NSDictionary alloc] init] autorelease]. Same for NSArray and friends.


Regards,
Duncan

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSData, chars, and torrent files
      • From: Bill Bumgarner <email@hidden>
References: 
 >NSData, chars, and torrent files (From: Jon Shier <email@hidden>)

  • Prev by Date: Re: IB: subclassing NSAnimation problem
  • Next by Date: Re: NSData, chars, and torrent files
  • Previous by thread: NSData, chars, and torrent files
  • Next by thread: Re: NSData, chars, and torrent files
  • Index(es):
    • Date
    • Thread