ReadAllText does only return first line

I'm trying to replicate this PHP function with VB.net:

function getGiantsModMD5Hash($modFile)
{
$info = pathinfo($modFile);
// Add mod zip data
$fileContent = file_get_contents($modFile);
// Add basefile name string without extension
$fileContent .= basename($modFile, '.' . $info['extension']);
return md5($fileContent);
}

From my understanding the function FileSystem.ReadAllText is most equivalent to the file_get_contents function in PHP. But when i use it it doesn't work, it only seems to return the first line. I've tried adding Encoding.Default, Encoding.UTF8 and so on, none seem to work.

Here's my code for reading the file (in this case, it's a .zip file)

Dim createHash As String
createHash = My.Computer.FileSystem.ReadAllText(modsPath & modName & ".zip") & modName
Form1.TextBox1.Text = createHash                ' Show result of ReadAllText to my eye

Any idea of how i can get this to work?

UPDATE:

This is the "format" of the data i need:

PKHr�F���Q��U   brand.dds훻    
�1�W�4���o`ao�al��ZX��C|@��-A��)���b��:d�39's�hVQ9�G&�ɹ��3��]�q��j�:{����     
�S�������a�e���ߵ[7����]�

... And so on

That is what it looks like when i print the result of the PHP file_get_contents function. (File is a .zip)

What i need to do is to take that info and add the filename without the extension of the file to it and calculate an MD5 hash, so i can compare that value to an already existing MD5 hash.

I've been googling for hours now whiteout finding any solution. Seems so simple with PHP but looks almost impossible to replicate with VB.NET? :(

Jon Skeet
people
quotationmark

A zip file is not a text file, so don't try to use it as if it were. It's vitally important that you distinguish between text data and binary data - not just here, but all over the place.

Hashing a file is simple though. Unfortunately as you're appending the filename that makes things slightly more complicated, but it's not too bad. Here's the C# code that hopefully you can port to VB easily enough (you'll use exactly the same methods and types):

byte[] HashFileWithName(string filename)
{
    using (var md5 = Md5.Create())
    {
        using (var stream = File.OpenRead(filename))
        {
            byte[] buffer = new byte[1024];
            int bytesRead;
            while ((bytesRead = stream.Read(buffer, 0, 1024)) != 0)
            {
                md5.TransformBlock(buffer, 0, bytesRead, null, 0);
            }
            string nameToHash = Path.GetFileNameWithoutExtension(filename);
            md5.TransformFinalBlock(Encoding.UTF8.GetBytes(nameToHash));
            return md5.Hash;
        }
    }
}

You may want to adjust the encoding of the filename, although it's unlikely to matter unless the filename contains non-ASCII characters.

people

See more on this question at Stackoverflow