Jump to content
  • Advertisement
Sign in to follow this  
Spa8nky

Using GZipStream to compress an XML file?

This topic is 2646 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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!