Skip to content

Instantly share code, notes, and snippets.

@ninjarobot
Last active May 16, 2016 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninjarobot/5b67644b792d52f8a76417a2c64088a0 to your computer and use it in GitHub Desktop.
Save ninjarobot/5b67644b792d52f8a76417a2c64088a0 to your computer and use it in GitHub Desktop.
Git object hash in FSharp
let calcObjHash (objData:byte array) =
use sha1 = new System.Security.Cryptography.SHA1Managed ()
let pre =
sprintf "blob %d\000" objData.Length
|> System.Text.Encoding.UTF8.GetBytes
use ms = new System.IO.MemoryStream ()
ms.Write (pre, 0, pre.Length)
ms.Write (objData, 0, objData.Length)
ms.Position <- 0L
sha1.ComputeHash (ms)
|> BitConverter.ToString
|> fun s -> s.Replace("-", "").ToLower ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment