Topic: Visual C# pack() function

Hey guys,
I'm looking for a pack() function in C#, similar to PHP's pack() function.
Would be handy if it existed...

Thanks alot,

-- Bekko

Re: Visual C# pack() function

there's no pack equiv.  you'll have to serialize it by hand that way.  If I get a few minutes I'll see if I can cook something up.

Re: Visual C# pack() function

Have a look at System.Runtime.Serialization and System.Runtime.Serialization.Formatters.Binary.BinaryFormatter in particular.
It is a whole different way of thinking than with PHP's pack() as C# is OO and each object is responsible for its own serialization.

Re: Visual C# pack() function

Hrmm, thanks, but since I'm trying to port an ID3 reader from PHP to C#, it's kinda hard to go from pack() to the BinaryFormatter =P

But if you can point me in the right direction for an ID3 reader... big_smile

5 (edited by MadHatter 2006-08-04 14:14)

Re: Visual C# pack() function

if you know what is where, the FileStream class lets you read byte by byte from the file. 

using ( Stream mp3 = File.OpenRead("song.mp3") ) {
    byte[] buffer = new byte[4096];
    s.Read(buffer, 0, buffer.Length);
    // you can also read specific areas:
    buffer = new byte[128];
    int start = 4097;
    int lengthToRead = buffer.Length;
    s.Read(buffer, start, lengthToRead);
}

there's already id3 readers/ writers out there in C#, and if you didnt want to use them, then they should help  you out with where to read / write.  http://sourceforge.net/projects/csid3lib/

Re: Visual C# pack() function

If that library works with .NET, I'll definately try it out big_smile Thanks!

Re: Visual C# pack() function

yea its all in C#

Re: Visual C# pack() function

This is probably a n00bish error, but the library refuses to read the ID3v1 tag (and yes, it's there, I checked with Winamp).
Here's my code:

/* Initialise tagreader */
            ID3v1 tagreader = new ID3v1();
            /* Open file stream */
            StreamReader file = new StreamReader("C:/Documents and Settings/El Bekko/My Documents/My Music/AC-DC/Stiff Upper Lip/09 Damned.mp3");
            
            /* Get ID3v1 info from file. */
            try
            {
                tagreader.Deserialize(file.BaseStream);
                textBox2.Text += "\r\nID3 Information: \r\nArtist: " + tagreader.Artist + "\r\n";
            }
            catch
            {
                textBox2.Text += "No ID3v1 Information found in file.\r\n";
            }

9 (edited by MadHatter 2006-08-04 15:44)

Re: Visual C# pack() function

looks like you should use tagmanager to deserialize the mp3.

ID3v1 id3 = new ID3v1();
using ( Stream s = File.OpenRead(@"\\dc01\DUMP\MP3\Tool\Opiate\Tool - Opiate - 01 - sweat.mp3") ) {
    TagManager mgr = new TagManager();
    id3.TagModel = mgr.Deserialize(s);
}
artistTextBox.Text = id3.Artist;
// ...

Re: Visual C# pack() function

Hey, thanks smile

Re: Visual C# pack() function

Here's the result of your help:
http://icstrategy.midgetforhire.com/Tools/ID3Lister.zip
Note, I just zipped up the 'publish' directory tongue

Re: Visual C# pack() function

very cool! 

I've never tried to use the click once publishing (dont trust it personally), but it ran pretty good.

Re: Visual C# pack() function

I agree with MadHatter, cool app!

Looking for a certain modification for your forum? Please take a look here before posting.

Re: Visual C# pack() function

Thanks big_smile

Re: Visual C# pack() function

Reminds me of a small C app I wrote in 2000. It inserted ID3 tags by "guessing" the title, artist, tracknumber and so on via the file and folder name smile

"Programming is like sex: one mistake and you have to support it for the rest of your life."