LazyApiPack.XmlTools.Zip
0.1.5
See the version list below for details.
dotnet add package LazyApiPack.XmlTools.Zip --version 0.1.5
NuGet\Install-Package LazyApiPack.XmlTools.Zip -Version 0.1.5
<PackageReference Include="LazyApiPack.XmlTools.Zip" Version="0.1.5" />
paket add LazyApiPack.XmlTools.Zip --version 0.1.5
#r "nuget: LazyApiPack.XmlTools.Zip, 0.1.5"
// Install LazyApiPack.XmlTools.Zip as a Cake Addin
#addin nuget:?package=LazyApiPack.XmlTools.Zip&version=0.1.5
// Install LazyApiPack.XmlTools.Zip as a Cake Tool
#tool nuget:?package=LazyApiPack.XmlTools.Zip&version=0.1.5
About this project
This library enables class serialization to a zip file. The class is serialized with the ExtendedXmlSerializer and the resources within the class (ZipResource) are stored as separate files within the zip file.
How to design a Zip serializable class
[XmlClass] // Marks this class as serializable (ExtendedXmlSerializer)
public class ImageModel {
List<ZipResource> _images = new List<ZipResource>();
[XmlArray("Images")]
[XmlArrayItem("Image")]
public List<ZipResource> Images { get => _images; set => _images = value; } // A list of resources
private ZipResource _mainImage;
[XmlAttribute]
public ZipResource MainImage { get => _mainImage; set => _mainImage=value; } // A resource can be an attribute!
}
To fill the resource with data, just set the property with
_model.MainImage = new ZipResource(streamOrByteArrayOfResource);
or
_model.MainImage.SetStream(streamOfResource);
or
_model.MainImage.Data = byteArrayOfResource;
How to serialize to a Zip file
var xmlSerializer = new ExtendedXmlSerializer<ImageModel>(); // Create the xml serializer and configure it as you like
var zipSerializer = new ZipSerializer<ImageModel>(xmlSerializer); // Create the zip serializer and configure it as you like
var strm = zipSerializer.Serialize(_model, true, System.IO.Compression.CompressionLevel.Optimal); // Serialize the model
How to deserialize from a Zip file
var xmlSerializer = new ExtendedXmlSerializer<ImageModel>(); // Create the xml serializer and configure it as you like
var zipSerializer = new ZipSerializer<ImageModel>(xmlSerializer); // Create the zip serializer and configure it as you like
var deserialized = zipSerializer.Deserialize(strm);
Compression and performance
You can optimize the serializer in two ways:
- CompressionLevel: the .NET zip archive uses this to configure the compression algorithm
- CheckDuplicates: the serializer will compare every resource and calculates a sha256 hash. If a resource produces the same hash, the serializer will not store this resource in the zip file but will use the existing file instead.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- LazyApiPack.XmlTools (>= 0.1.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Introduces support to deserialize a list of classes directly.
Adds support to deserialize a property of a type that does not exactly match the object its holding (eg. the property class type is used as a base class but not marked as abstract).