forked from SolrNet/SolrNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompressionUtils.cs
37 lines (29 loc) · 932 Bytes
/
CompressionUtils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System.IO;
using System.IO.Compression;
using System.Text;
namespace SolrNet.Tests.Utils
{
public class CompressionUtils
{
public static Stream GzipCompressStream(string textToCompress)
{
var data = Encoding.GetEncoding("iso-8859-1").GetBytes(textToCompress);
using (var ms = new MemoryStream()) {
using (var zip = new GZipStream(ms, CompressionMode.Compress)) {
zip.Write(data, 0, data.Length);
}
return new MemoryStream(ms.ToArray());
}
}
public static Stream DeflateCompressStream(string textToCompress)
{
var data = Encoding.GetEncoding("iso-8859-1").GetBytes(textToCompress);
using (var ms = new MemoryStream()) {
using (var zip = new DeflateStream(ms, CompressionMode.Compress)) {
zip.Write(data, 0, data.Length);
}
return new MemoryStream(ms.ToArray());
}
}
}
}