[Mono-list] Question about encoding and tricky stuff.
    Rampage 
    atomikramp at email.it
       
    Tue Aug 24 06:05:20 EDT 2010
    
    
  
Christopher David Howie wrote:
> 
> On 08/23/2010 08:25 PM, Rampage wrote:
>> this way the hash matches perfectly but obviously once the stream is read
>> it's gone, and since i need both to render the image and calculate the
>> md5
>> it's going to be an issue.
>> 
>> do you have anything to suggest me?
> 
> Stream stream; // this is your input stream
> 
> var md5 = MD5.Create();
> using (var wrap = new CryptoStream(stream, md5,
>                                    CryptoStreamMode.Read)) {
>     // Process the "wrap" stream how you would process the original data
>     // stream.
> 
>     wrap.FlushFinalBlock();
> 
>     // The "md5" object contains the hash state.
> }
> 
> 
> 
i've found these snipplets by googling around and they seem to work
properly:
---------------------------
public static void CopyStream(Stream input, Stream output)
{
    byte[] b = new byte[32768];
    int r;
    while ((r = input.Read(b, 0, b.Length)) > 0)
        output.Write(b, 0, r);
}
public static byte[] StreamToByte(Stream streaminput)
{
    MemoryStream mem = new MemoryStream();
    CopyStream(streaminput, mem);
    return mem.ToArray();
}
--------------------------------
Thanks for the help
-- 
View this message in context: http://mono.1490590.n4.nabble.com/Question-about-encoding-and-tricky-stuff-tp2335084p2336403.html
Sent from the Mono - General mailing list archive at Nabble.com.
    
    
More information about the Mono-list
mailing list