Section 1
Compress or decompress stream information in a .NET Framework application (refer System.IO.Compression namespace), and improve the security of application data by using isolated storage. (Refer System.IO.IsolatedStorage namespace)
- IsolatedStorageFile class
- IsolatedStorageFileStream class
- DeflateStream class
- GZipStream class
Summary
The IsolatedStorageFile Class and the IsolatedStorageFileStream Class represent specific isolated storage locations. Isolated storage is just a location on your hard drive that only your application can see. The operating system manages access to this location. With Isolated Storage, “you can read and write data that less trusted code cannot access and prevent the exposure of sensitive information that can be saved elsewhere on the file system. Data is stored in compartments that are isolated by the current user and by the assembly in which the code exists. Additionally, data can be isolated by domain. Roaming profiles can be used in conjunction with isolated storage so isolated stores will travel with the user's profile.” (msdn2)
The DeflateStream Class is new to .Net 2.0 and is used for compressing and decompressing streams using the Deflate Algorithm. An example of deflating and inflating a dataset with this class is below. It is taken from the Compressing Persisted DataSets article listed in the resources section.
outfile = New FileStream("test.xmd", FileMode.Create, FileAccess.Write)
DefStream = New DeflateStream(outfile, CompressionMode.Compress, False)
ds.WriteXml(DefStream) infile = New FileStream("test.xmd", FileMode.Open, FileAccess.Read)
DefStream = New DeflateStream(infile, CompressionMode.Decompress, False)
ds.ReadXml(DefStream)
The GZipStream Class is new to .Net 2.0 and is used for compressing and decompressing streams using the GZip format. This Class is extensible but it comes at the cost of being slightly slower that the DeflateStream Class. An example of deflating and inflating a dataset with this class is below.
outfile = New FileStream("test.xmd", FileMode.Create, FileAccess.Write)
gZipStream = New GZipStream(outfile, CompressionMode.Compress, False)
ds.WriteXml(gZipStream) infile = New FileStream("test.xmd", FileMode.Open, FileAccess.Read)
gZipStream = New GZipStream(infile, CompressionMode.Decompress, False)
ds.ReadXml(gZipStream)
Other Resources & Links:
Understanding Isolated Storage
http://www.dotnetdevs.com/articles/IsolatedStorage.aspx
System.IO.IsolatedStorage Namespace
http://msdn2.microsoft.com/en-us/library/system.io.isolatedstorage(VS.80).aspx
IsloatedStorageFile Class
http://msdn2.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile(VS.80).aspx
IsolatedStorageFileStream Class
http://msdn2.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefilestream(VS.80).aspx
Compressing Persisted DataSets
http://www.codeproject.com/dotnet/CompressedDataSets.asp
DeflateStream Class
http://msdn2.microsoft.com/en-us/library/system.io.compression.deflatestream(VS.80).aspx
GZipStream Class
http://msdn2.microsoft.com/en-us/library/system.io.compression.gzipstream(VS.80).aspx