Save disk space with IsolatedStorageGZipFileStream

Unfortunatly, our Windows Phone does not have so much space in the SD Card, LG has furnished 16 Gb, but generally, we have 8Gb. That is not too much, especially when we have a Zune Pass / many songs and movies...

In this case, in our applications, we must be careful with the isolatedstorage... the SD Card can be rapidelly full :s

So, thanks to the .net framework and the stream object. I developped an IsolatedStorageGZipFileStream object that can save and compress (GZip) your objects in the isolated storage.

This was pretty easy to code it. I took the GZipStream class from the .net Framework source (may be I should check the licence about it...) and I inherits from it:

 public class IsolatedStorageGZipFileStream : GZipStream
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="IsolatedStorageGZipFileStream"/> class.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="access">The access.</param>
        /// <param name="isf">The isf.</param>
        /// <param name="compressionMode">The compression mode.</param>
        public IsolatedStorageGZipFileStream(string path, FileMode mode, FileAccess access, IsolatedStorageFile isf, CompressionMode compressionMode)
            : base(new IsolatedStorageFileStream(path, mode, access, isf), compressionMode)
        {
 
        }
 
        /// <summary>
        /// Initializes a new instance of the <see cref="IsolatedStorageGZipFileStream"/> class.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="access">The access.</param>
        /// <param name="share">The share.</param>
        /// <param name="isf">The isf.</param>
        /// <param name="compressionMode">The compression mode.</param>
        public IsolatedStorageGZipFileStream(string path, FileMode mode, FileAccess access, FileShare share,
                                         IsolatedStorageFile isf, CompressionMode compressionMode)
            : base(new IsolatedStorageFileStream(path, mode, access, share, isf), compressionMode)
        {
 
        }
 
        /// <summary>
        /// Initializes a new instance of the <see cref="IsolatedStorageGZipFileStream"/> class.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="isf">The isf.</param>
        /// <param name="compressionMode">The compression mode.</param>
        public IsolatedStorageGZipFileStream(string path, FileMode mode, IsolatedStorageFile isf, CompressionMode compressionMode)
            : base(new IsolatedStorageFileStream(path, mode, isf), compressionMode)
        {
            
        }
    }

The IsolatedStorageGZipFileStream can easily be used with the Cache object (link here) by replacing IsolatedStorageFileStream with IsolatedStorageGZipFileStream.

The complete source code is of course available: Phone7.Fx.Preview.zip (100,38 kb)

If you have feedback, you are welcome !

Comments (2) -

Alden Radle
Alden Radle
8/30/2011 12:04:36 PM #

Hi there may I reference some of the information here in this site if I link back to you?

Nicolas Humann
Nicolas Humann
8/31/2011 6:24:22 PM #

Yes of course !

Pingbacks and trackbacks (1)+

Comments are closed

Hi there !

 

Specialized in .net technologies for many years, I am a technology fan in both asp.net and wpf/silverlight, using c# and .net 4.

Taking advantages of new opportunities offered by the Windows Azure platform and WP7, I develop applications for Windows 7 Phone, 2 of them are already available on the market place.


 

 

Month List