GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - helpermethod/zip-forge: A tiny, formatter-friendly Java DSL for creating ZIP files.

BranchesTags
Open more actions menu

Latest commit

 

History

255 Commits
255 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
.mvn
.mvn
 
 
src
src
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
mvnw
mvnw
 
 
mvnw.cmd
mvnw.cmd
 
 
pom.xml
pom.xml
 
 
renovate.json
renovate.json
 
 

Repository files navigation

🌋 ZIP Forge

CI

A tiny, formatter-friendly Java DSL for creating ZIP files.

✨ Features

🤏 Tiny

The ZIP Forge API consists of only 3 methods.

📋 Formatter-friendly

Applying a code formatter like palantir-java-format won't mess up ZIP Forge's indentation.

📦 No external dependencies

ZIP Forge is based on Java's ZIP File System Provider and requires no external dependencies.

🧩 Modular

ZIP Forge is published as a Java 9 module.

🛠️ Installation

Maven

<dependency>
    <groupId>io.github.helpermethod</groupId>
    <artifactId>zip-forge</artifactId>
    <version>2.0.0</version>
</dependency>

Gradle

implementation 'io.github.helpermethod:zip-forge:2.0.0'

Gradle (Kotlin)

implementation("io.github.helpermethod:zip-forge:2.0.0")

🔍 Usage

Java

The following code snippet calls createZipFile to create the ZIP file at the given location. It uses the file and directory methods to create files and directories within the context of the ZIP file.

Warning

file and directory should never be used outside of createZipFile's or directory's context.

import java.nio.charset.StandardCharsets;

import static io.github.helpermethod.zipforge.ZipForge.createZipFile;
import static io.github.helpermethod.zipforge.ZipForge.file;
import static io.github.helpermethod.zipforge.ZipForge.directory;
import static java.nio.charset.StandardCharsets.UTF_8;

class ZipForgeDemo {
    public static void main(String[] args) throws IOException {
        // creates a ZIP file named demo.zip in the /home/helpermethod directory
        createZipFile(Paths.get("/home/helpermethod/demo.zip"), () -> {
            // the file content can be specified as a String...
            file("a.txt", "a");
            directory("d", () -> {
                // ... or a byte[]...
                file("b.txt", "b".getBytes(UTF_8));
                // ... or a Path
                file("c.bin", Paths.get("c.bin"));
                // directories can be nested
                directory("e", () -> {
                    file("f.txt", "f");
                });
            });
        });
    }
}

The above code results in a ZIP file with the following structure.

Archive:  demo.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  07-11-2023 15:39   d/
        0  07-11-2023 15:39   d/e/
        1  07-11-2023 15:39   a.txt
        1  07-11-2023 15:39   d/b.txt
        1  07-11-2023 15:39   d/c.bin
        1  07-11-2023 15:39   d/e/f.txt
---------                     -------
        4                     6 files

Kotlin

The same example written in Kotlin.

import io.github.helpermethod.zipforge.ZipForge.createZipFile
import io.github.helpermethod.zipforge.ZipForge.directory
import io.github.helpermethod.zipforge.ZipForge.file
import kotlin.io.path.Path

fun main() {
    createZipFile(Path("/home/helpermethod/demo.zip")) {
        file("a.txt", "a")
        directory("d") {
            file("b.txt", "b".toByteArray())
            file("c.bin", Path("c.bin"))
            directory("e") {
                file("f.txt", "f")
            }
        }
    }
}

About

A tiny, formatter-friendly Java DSL for creating ZIP files.

Topics

dslgroovyjavajava-17kotlinzipfile

Resources

Readme
Apache-2.0 license
Activity

Stars

40 stars

Watchers

2 watching

Forks

2 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.