By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,467 Members | 1,619 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,467 IT Pros & Developers. It's quick & easy.

serialize list in a zip?

P: n/a
Hi,
I would like to solve a problem.
Normally in my code I use this:
----------------------------------------
public void SaveFileCat(string path)
{
Stream myfile;
IFormatter formatter = new BinaryFormatter();
if(File.Exists(path))
{
myfile = new FileStream(path, FileMode.Truncate, FileAccess.Write);
}
else
myfile = new FileStream(path, FileMode.CreateNew, FileAccess.Write);

formatter.Serialize(myfile, listCat);
myfile.Close();
}
-------------------------------------------
The problem:
serialized files could to be up to 1 MB long, it depend from archive lenght.

In #develop there's #ziplib, but I don't know how to make it,
or better, I tried to make it, but only with normal file is simple.
There are other ways to make it?

Thanks you
frazan
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

Since this is a single file that you have control over reading/writing
you can use GZipOutputStream to compress the data. Just change

formatter.Serialize(myfile, listCat);
myfile.Close();

to

Stream zs = new GZipOutputStream(myfile);
formatter.Serialize(zs, listCat);
zs.Close()

The change to the load routine is pretty much the same, just use
GZipInputStream wrapped around the file stream before passing to
Deserialize.

The docs that come with #ziplib may be a little light but they do have
examples of this.

HTH,

Sam
On Sun, 6 Mar 2005 18:42:10 +0100, "frazan" <fr******@hotmail.com>
wrote:
Hi,
I would like to solve a problem.
Normally in my code I use this:
----------------------------------------
public void SaveFileCat(string path)
{
Stream myfile;
IFormatter formatter = new BinaryFormatter();
if(File.Exists(path))
{
myfile = new FileStream(path, FileMode.Truncate, FileAccess.Write);
}
else
myfile = new FileStream(path, FileMode.CreateNew, FileAccess.Write);

formatter.Serialize(myfile, listCat);
myfile.Close();
}
-------------------------------------------
The problem:
serialized files could to be up to 1 MB long, it depend from archive lenght.

In #develop there's #ziplib, but I don't know how to make it,
or better, I tried to make it, but only with normal file is simple.
There are other ways to make it?

Thanks you
frazan


B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
Nov 16 '05 #2

P: n/a
It's ok!!! :) Is two days that I put my head on the wall, and it's so
simple!!
I was testing MemoryStream but this bring me on wrong way, I obtain this
error:
"End of Stream encountered before parsing was completed".

Very very Thanks!!! If you come in Italy I will offer you a beer! :))

frazan

"Samuel R. Neff" <bl****@newsgroup.nospam> ha scritto nel messaggio
news:e1********************************@4ax.com...

Since this is a single file that you have control over reading/writing
you can use GZipOutputStream to compress the data. Just change

formatter.Serialize(myfile, listCat);
myfile.Close();

to

Stream zs = new GZipOutputStream(myfile);
formatter.Serialize(zs, listCat);
zs.Close()

The change to the load routine is pretty much the same, just use
GZipInputStream wrapped around the file stream before passing to
Deserialize.

The docs that come with #ziplib may be a little light but they do have
examples of this.

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.