LazyApiPack.XmlTools.Zip 0.1.7.1

dotnet add package LazyApiPack.XmlTools.Zip --version 0.1.7.1
NuGet\Install-Package LazyApiPack.XmlTools.Zip -Version 0.1.7.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LazyApiPack.XmlTools.Zip" Version="0.1.7.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LazyApiPack.XmlTools.Zip --version 0.1.7.1
#r "nuget: LazyApiPack.XmlTools.Zip, 0.1.7.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LazyApiPack.XmlTools.Zip as a Cake Addin
#addin nuget:?package=LazyApiPack.XmlTools.Zip&version=0.1.7.1

// Install LazyApiPack.XmlTools.Zip as a Cake Tool
#tool nuget:?package=LazyApiPack.XmlTools.Zip&version=0.1.7.1

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 with the ZipResource 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 design a Zip serializable class with byte[]

    [XmlClass] // Marks this class as serializable (ExtendedXmlSerializer)
    public class ImageModel {
        List<byte[]> _images = new List<byte[]>();
        [XmlArray("Images")]
        [XmlArrayItem("Image")]
        public List<byte[]> Images { get => _images; set => _images = value; } // A list of resources

        private byte[] _mainImage;
        [XmlAttribute]
        public byte[] 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 = 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);

Prevent serialization of byte[] to zip

If you want to store the type byte[] regularly as base64 within the xml file and only store properties of the type ZipResource to the zip file, you can use the parameter 'byteArrayAsZipEntry' when calling Serialize() and Deserialize()

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.7.1 167 5/22/2023
0.1.7 310 12/4/2022
0.1.6 281 12/3/2022
0.1.5 301 11/20/2022
0.1.4 292 11/18/2022
0.1.2 315 11/15/2022

Dependencies cleanup.