Giter VIP home page Giter VIP logo

llziplib's Introduction

LLZipLib

Low level Zip Library, allowing advanced tweaks (injecting/removing extra blocks, altering flags, crafting special archives). Self contained, no third party dependencies. If you just want to unzip files, this is not for you :)

.ZIP File Format Specification: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT

How to use it:

Changing file content

var zip = ZipArchive.Read(filename);

var entry = zip.Entries.FirstOrDefault(e => e.LocalFileHeader.Filename == "readme.txt");
if (entry != null)
{
	entry.Data = zip.StringConverter.GetBytes("This is my new content", StringConverterContext.Content);
	// this is not compressed
	entry.LocalFileHeader.Compression = entry.CentralDirectoryHeader.Compression = 0;
}

zip.Write(filename);

Processing file names

var zip = ZipArchive.Read(filename);

foreach (var entry in zip.Entries)
{
	entry.LocalFileHeader.Filename = "foo." + entry.LocalFileHeader.Filename;
	entry.CentralDirectoryHeader.Filename = entry.LocalFileHeader.Filename;
}

zip.Write(filename);

Creating archive / adding entry

var zip = new ZipArchive();
var entry = new ZipEntry();

zip.Entries.Add(entry);
entry.LocalFileHeader.Filename = entry.CentralDirectoryHeader.Filename = "foo.txt";
entry.Data = zip.StringConverter.GetBytes("Hello world!", StringConverterContext.Content);

zip.Write("foo.zip");

Removing all data descriptors

var zip = ZipArchive.Read(filename);

foreach (var entry in zip.Entries.Where(entry => entry.HasDataDescriptor))
{
	entry.LocalFileHeader.CompressedSize = entry.DataDescriptor.CompressedSize;
	entry.LocalFileHeader.UncompressedSize = entry.DataDescriptor.UncompressedSize;
	entry.LocalFileHeader.Crc = entry.DataDescriptor.Crc;
	entry.HasDataDescriptor = false; 
}

zip.Write(filename);

Removing all extra blocks

var zip = ZipArchive.Read(filename);

foreach (var entry in zip.Entries)
{
	entry.LocalFileHeader.Extra = new byte[0];
	entry.CentralDirectoryHeader.Extra = new byte[0];
}

zip.Write(filename);

llziplib's People

Contributors

sailro avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.