GithubHelp home page GithubHelp logo

helpermethod / zip-forge Goto Github PK

View Code? Open in Web Editor NEW
36.0 4.0 2.0 143 KB

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

License: Apache License 2.0

Java 100.00%
dsl groovy java kotlin zipfile java-8

zip-forge's Introduction

๐ŸŒ‹ ZIP Forge

CI Security Rating Maintainability Rating Reliability Rating Coverage

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 will not 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 but compatible with Java 8.

๐Ÿ› ๏ธ Installation

Maven

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

Gradle

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

Gradle (Kotlin)

implementation("io.github.helpermethod:zip-forge:1.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. It uses the same API as the Java version.

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")
            }
        }
    }
}

zip-forge's People

Contributors

akashpambhar avatar dependabot[bot] avatar helpermethod avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

zip-forge's Issues

Add support for large files

Add another file overload which accepts an InputStream, something like

public static void file(String name, InputStream content)

Switch to Renovate

In contrast to Dependabot, Renovate is also able to keep the Maven wrapper up-to-date.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • actions/setup-java v4
  • actions/cache v4
  • ubuntu 22.04
.github/workflows/release.yml
  • actions/checkout v4
  • actions/setup-java v4
  • ubuntu 22.04
maven
pom.xml
  • org.junit.jupiter:junit-jupiter 5.10.2
  • org.assertj:assertj-core 3.26.0
  • org.apache.maven.plugins:maven-deploy-plugin 3.1.2
  • org.sonarsource.scanner.maven:sonar-maven-plugin 4.0.0.4121
  • org.apache.maven.plugins:maven-jar-plugin 3.4.2
  • org.apache.maven.plugins:maven-compiler-plugin 3.13.0
  • org.apache.maven.plugins:maven-surefire-plugin 3.3.0
  • org.apache.maven.plugins:maven-toolchains-plugin 3.2.0
  • com.diffplug.spotless:spotless-maven-plugin 2.43.0
  • org.jreleaser:jreleaser-maven-plugin 1.12.0
  • org.jacoco:jacoco-maven-plugin 0.8.12
  • org.moditect:moditect-maven-plugin 1.2.1.Final
  • org.apache.maven.plugins:maven-javadoc-plugin 3.7.0
  • org.apache.maven.plugins:maven-source-plugin 3.3.1
maven-wrapper
.mvn/wrapper/maven-wrapper.properties
  • maven 4.0.0-beta-3
  • maven-wrapper 3.3.2

  • Check this box to trigger a request for Renovate to run again on this repository

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.