473,394 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

serialize list in a zip?

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
2 2018

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Iyer, Prasad C | last post by:
Hi, I got a class which I need to serialize, except for couple of variable. i.e. import cPickle as p class Color: def __init__(self): print "hello world" self.x=10 self.somechar="this are...
1
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
1
by: Craig Buchanan | last post by:
I am trying to serialize a class called Order to the ViewState. Order has one property called LineItems, which is an ArrayList. The ArrayList holds instances of a class named LineItem. Bother...
17
by: Peter | last post by:
How would would you deserialize this example below? Imports System Imports System.Collections Imports System.IO Imports System.Xml.Serialization Public Class App1 Shared Sub Main()
0
by: Tim_Mac | last post by:
hi, i am able to serialize a normal generic List<> no problem. But when i try to serialize a Dictionary<string,string>, i get an exception as shown below: "The type...
3
by: Mirek Endys | last post by:
What is the best way to serialize object, that contains data in interfaces. Simple. I have instance of my object, that contains data in interfaces. What is the best way to XMLSerialize and...
2
by: Jinsong Liu | last post by:
I have following 3 classes public class MyMainClass { MyCollection<MyObject> m_oMyObjectCollection = null; private string m_sID = string.Empty; public MyCollection<MyObject> Collection {
1
by: Rick Luckwell | last post by:
I have 3 collections(reports, services, charts) of objects(report, service, chart) that are nested with each other. When I serialize the object the output only contains reports and services but...
2
by: Joe | last post by:
Hi I have a Generics List in a PropertyGrid I am able to Serialize it to XML but when I try to deserialize back to the class of the PropertyGrid The Constructor doesn't seem to fire to reload...
9
by: Gillard | last post by:
i get an exeption and i do not know what else to do to continue Dim sdf As New SaveFileDialog With sdf .AddExtension = True .DefaultExt = ".record" .FileName = Now.ToLongDateString .Filter =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.