/// <summary> /// 取文件MD5值 /// </summary> /// <param name="stream"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> public static string FileMD5(Stream stream) { if (!stream.TrySeek()) return string.Empty; byte[] bs = MD5.Create().ComputeHash(stream); stream.TrySeek(); return BitConverter.ToString(bs).Replace("-", ""); }
/// <summary> /// 通过文件头取扩展名编号 /// </summary> /// <param name="stream"></param> /// <returns></returns> public static string GetFileCode(Stream stream) { if (!stream.TrySeek()) return string.Empty; var r = new BinaryReader(stream); byte buffer = r.ReadByte(); string bx = buffer.ToString("D3"); buffer = r.ReadByte(); bx += buffer.ToString("D3"); stream.TrySeek(); return bx; }