Zip content file

I want to know if theres a way to just load files from a zip file

This is a class from a test I did a while ago, it might have some bugs, but it will give you a start

You will need to reference ICSharpCode.SharpZipLib https://icsharpcode.github.io/SharpZipLib/

Password zip files where not implemented but can be added quickly.

/**
* Copyright 2013 Nathan ‘Grimston’ Pipes
* Custom ContentManager, that supports zip files, and passwords
**/
using System;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace MonoGameTest
{
    class ZipContentManager : ContentManager
    {
        private bool usingZip = false;

        private string contentPath;

        private string zipPassword = "";

        public string ZipPassword {
            get { return zipPassword; }
            set { zipPassword = value; }
        }

        public string ContentPath {
            get { return contentPath; }
            set { contentPath = value; }
        }

        public bool UsingZip {
            get { return usingZip; }
            set { usingZip = value; }
        }

        internal ZipFile zipFile;

        public ZipContentManager(GameServiceContainer gsc, string contentPath):base(gsc)
        {
            if (Directory.Exists (contentPath) || File.Exists(contentPath)) {
                //Path Exists, Is it a file?
                this.contentPath = contentPath;
                if (File.Exists(contentPath)) {
                    //Its a file! Is it a zip file?
                    if (Path.GetExtension(contentPath) == ".zip") {
                        //Yes! We are using compressed content
                        usingZip = true;
                        zipFile = new ZipFile(contentPath);

                    }
                }
            }
        }

        protected override Stream OpenStream(string assetName)
        {
            if (usingZip)
            {
                int entry = zipFile.FindEntry(assetName, true);
                if (entry != -1)
                    return zipFile.GetInputStream(entry);
                else
                {
                    entry = zipFile.FindEntry(assetName + ".xnb", true);
                    if (entry != -1)
                        return zipFile.GetInputStream(entry);
                }
            }
            else
            {
                if(File.Exists(Path.Combine(contentPath, assetName)))
                    return new FileStream(Path.Combine(contentPath, assetName), FileMode.Open, FileAccess.Read, FileShare.None);
            }

            return base.OpenStream("Content/" + assetName);
        }
    }
}

Any different LZ4 vs sharpziplib?

LZ4Net is just LZ4 compression/decompression. It doesn’t deal with zip-files which are fully structured and path designated, example: a zip file may contain numerous “files” under a path designation (it’s still a flat tree). LZ4 while usable for zip file compression just operates on a blob of data, there will be no structure that you did not create yourself before compressing.

Edit: Ack! Necromancy!

which mean is not suitable for bundle few xnb asset into a single file? unity use LZ4 to bundle asset.
https://docs.unity3d.com/530/Documentation/Manual/AssetBundleCompression.html

Unity’s asset bundles are their own file format, so they can use any compression they want. We use LZ4 inside the XNB file when content compression is selected. What you want is a container format that allows many files to be inside a container file. Zip can be used for that, or you can provide your own container format. I have done both successfully in the past.

i was thinking can we use LZ4 as a container format?