aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Util.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r--OpenSim/Framework/Util.cs42
1 files changed, 42 insertions, 0 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 719dda6..a835cec 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.Data; 29using System.Data;
30using System.IO; 30using System.IO;
31using System.IO.Compression;
31using System.Net; 32using System.Net;
32using System.Net.Sockets; 33using System.Net.Sockets;
33using System.Reflection; 34using System.Reflection;
@@ -618,6 +619,47 @@ namespace OpenSim.Framework
618 return ret; 619 return ret;
619 } 620 }
620 621
622 public static string Compress(string text)
623 {
624 byte[] buffer = Encoding.UTF8.GetBytes(text);
625 MemoryStream memory = new MemoryStream();
626 using (GZipStream compressor = new GZipStream(memory, CompressionMode.Compress, true))
627 {
628 compressor.Write(buffer, 0, buffer.Length);
629 }
630
631 memory.Position = 0;
632 MemoryStream outStream = new MemoryStream();
633
634 byte[] compressed = new byte[memory.Length];
635 memory.Read(compressed, 0, compressed.Length);
636
637 byte[] compressedBuffer = new byte[compressed.Length + 4];
638 System.Buffer.BlockCopy(compressed, 0, compressedBuffer, 4, compressed.Length);
639 System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, compressedBuffer, 0, 4);
640 return Convert.ToBase64String(compressedBuffer);
641 }
642
643 public static string Decompress(string compressedText)
644 {
645 byte[] compressedBuffer = Convert.FromBase64String(compressedText);
646 using (MemoryStream memory = new MemoryStream())
647 {
648 int msgLength = BitConverter.ToInt32(compressedBuffer, 0);
649 memory.Write(compressedBuffer, 4, compressedBuffer.Length - 4);
650
651 byte[] buffer = new byte[msgLength];
652
653 memory.Position = 0;
654 using (GZipStream decompressor = new GZipStream(memory, CompressionMode.Decompress))
655 {
656 decompressor.Read(buffer, 0, buffer.Length);
657 }
658
659 return Encoding.UTF8.GetString(buffer);
660 }
661 }
662
621 public static string[] ParseStartLocationRequest(string startLocationRequest) 663 public static string[] ParseStartLocationRequest(string startLocationRequest)
622 { 664 {
623 string[] returnstring = new string[4]; 665 string[] returnstring = new string[4];