Jump to content
  • Advertisement
Sign in to follow this  
Spa8nky

Using GZipStream to compress an XML file?

This topic is 2560 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently saving my files using the XmlWriter class in .NET:



SaveData saveData = new SaveData();
game.WriteObjects(ref saveData);

Stream stream;

SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.AddExtension = true;
saveFileDialog.CheckFileExists = false;
saveFileDialog.CheckPathExists = true;
saveFileDialog.InitialDirectory = Application.StartupPath;
saveFileDialog.Filter = "XML files (*.xml)|*.xml";
saveFileDialog.FilterIndex = 2;
saveFileDialog.RestoreDirectory = true;

if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if ((stream = saveFileDialog.OpenFile()) != null)
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.ConformanceLevel = ConformanceLevel.Auto;
settings.Encoding = System.Text.Encoding.UTF8;
settings.Indent = true;

using (XmlWriter xmlWriter = XmlWriter.Create(stream, settings))
{
saveDataSerializer.Serialize(xmlWriter, saveData);
}

using (GZipStream compressedStream = new GZipStream(stream, CompressionMode.Compress, false))
{
//compressedStream.Write(buffer, 0, buffer.Length);
}

stream.Close();
}
}


How can I compress the .XML file as it is written (so it is saved as a compressed file) using GZipStream? I think I require a byte array but I don't know how to access that when using XmlWriter.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!