[SPAM] RE: [BitTorrent] Follow up: Are metainfo (.torrent) files text files ? ;)

Marcel Popescu mdpopescu at yahoo.com
Mon Nov 22 12:42:00 EST 2004

> From: skybuckflying [mailto:skybuck2000 at hotmail.com]

> I think this is quite dangerous since some language like delphi and C
> use char(0) to indicate the end of a string.

Delphi does no such thing. On the other hand, you can be excused for
believing this, given that even some of those at Borland who wrote the
Delphi VCL made this mistake...

Delphi appends a Char(0) at the end of the string so that you can pass a
C-style string to Windows API functions easily, using PChar (s). But Delphi
knows the end of the string because it prepends its length to it - it
doesn't use the Char(0) to determine it. (Again, excluding the functions
written by the idiot who confused the two.)

> Fortunately delphi's native string type works with "length prefixes".
> But it could also be typecasted to a Pchar which works like a null
> terminated character.

Sorry, I should have read some more :)

> Fortunately for me... I code in delphi and I will prevent to usage of
> Pchars in my "soon to be" TmetaInfo class ;)

> The funny thing is I actually found a bug in Delphi's TstringList
> It tries to turn the string that it read into multiple strings when
> #0, #10 or #13 is encountered

Not entirely a bug, wrt #10 and #13 those are the specs. Don't use
TStringLists, use a simple string.

> It starts with a while loop that checks for #0... if it encounters
> this character it simply stops... apperently the borland coder didn't
> expect the first character to be #0 and the rest to be text :)

As I said, some Borland programmers didn't think straight when it comes to
> My final conclusion and advice is: don't try processing
> torrent/metainfo files as text files with Delphi ;) and possibly
> other languages... :D

Wrong, Delphi's just fine, as long as you don't use the buggy parts. Use

This is what I'm using to read files of any kind - it has no problem with

  function      LoadFile (const pFileName: string): string;
    str         : TFileStream;

    Result := '';

    str := TFileStream.Create (pFileName, fmOpenRead or fmShareDenyNone);
      SetLength (Result, str.Size);
      str.Read (Result [1], Length (Result));



------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.

Yahoo! Groups Links

<*> To visit your group on the web, go to:

<*> To unsubscribe from this group, send an email to:
    BitTorrent-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:

More information about the BitTorrent mailing list