-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathUtils.cs
More file actions
48 lines (40 loc) · 1.34 KB
/
Utils.cs
File metadata and controls
48 lines (40 loc) · 1.34 KB
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
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.IO;
using System.IO.Compression;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace LumiSoft.MailServer.API.UserAPI
{
/// <summary>
/// Provides internal helper methods.
/// </summary>
internal class Utils
{
#region method CompressDataSet
/// <summary>
/// Decompresses specified DataSet data what is compressed with GZIP.
/// </summary>
/// <param name="source">Stream to decompress.</param>
/// <returns>Returns decompressed DataSet.</returns>
public static DataSet DecompressDataSet(Stream source)
{
source.Position = 0;
GZipStream gzip = new GZipStream(source,CompressionMode.Decompress);
MemoryStream retVal = new MemoryStream();
byte[] buffer = new byte[8000];
int readedCount = gzip.Read(buffer,0,buffer.Length);
while(readedCount > 0){
// Store current zipped data block
retVal.Write(buffer,0,readedCount);
// Read next data block
readedCount = gzip.Read(buffer,0,buffer.Length);
}
retVal.Position = 0;
DataSet ds = new DataSet();
ds.ReadXml(retVal);
return ds;
}
#endregion
}
}