Created
July 20, 2015 08:01
-
-
Save fairjm/6ae5e3d742dc3a0ef9ce to your computer and use it in GitHub Desktop.
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
open System.Text | |
open System.IO | |
open System.IO.Compression | |
let iso8859_1 = Encoding.GetEncoding("ISO-8859-1"); | |
let compress (s:string) = | |
let sBytes = Encoding.UTF8.GetBytes(s) | |
use original = new MemoryStream(sBytes) | |
let oBytes = using(new MemoryStream())(fun out -> | |
using(new GZipStream(out,CompressionMode.Compress))(fun gzip -> | |
original.CopyTo(gzip) | |
) | |
out.ToArray() | |
) | |
iso8859_1.GetString(oBytes) | |
let decompress (s:string) = | |
let sBytes = iso8859_1.GetBytes(s) | |
use compressed = new MemoryStream(sBytes) | |
let deBytes = using(new MemoryStream())(fun de -> | |
using(new GZipStream(compressed,CompressionMode.Decompress))(fun gzip -> | |
gzip.CopyTo(de) | |
) | |
de.ToArray() | |
) | |
Encoding.UTF8.GetString(deBytes) | |
[<EntryPoint>] | |
let main argv = | |
compress "just for test by fairjm" |> decompress |>printfn "%s" | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment