Created
December 7, 2016 18:35
-
-
Save smoothdeveloper/66ffb0be6d5d374d69aa2f219a09c1a8 to your computer and use it in GitHub Desktop.
IronFunctions help Seif Lotfy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// code converted for http://seif.codes/playing-with-net-dotnet-and-ironfunctions/ | |
// https://twitter.com/SeifLotfy/status/805901527659540480 | |
open System | |
open System.IO | |
open System.Security.Cryptography | |
open System.Text | |
let downloadRemoteImageFile (url: string) = | |
let request = url |> System.Net.WebRequest.CreateHttp | |
use response = request.GetResponseAsync().Result | |
use stream = response.GetResponseStream() | |
use memoryStream = new MemoryStream(Capacity = int response.ContentLength) | |
stream.CopyTo memoryStream | |
memoryStream.ToArray() | |
let isPipedInput () = | |
try | |
let _ = Console.KeyAvailable | |
false | |
with | |
| _ -> true | |
let createCheckSum (data: byte array) = | |
use md5 = MD5.Create() | |
let hash = md5.ComputeHash data | |
let builder = StringBuilder() | |
for b in hash do | |
sprintf "%x" b |> (builder.Append >> ignore) | |
builder.ToString() | |
[<EntryPoint>] | |
let main args = | |
if not (isPipedInput()) then | |
1 | |
else | |
Console.In.ReadToEnd() | |
|> downloadRemoteImageFile | |
|> createCheckSum | |
|> Console.WriteLine | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment